Created
April 28, 2013 10:44
-
-
Save danielpetisme/5476546 to your computer and use it in GitHub Desktop.
Design patterns are commons concepts for every devlopper. So I'm trying to implement the basic ones in Golo.
The very first one is the Singoloton but I'm facing some issues. 1 - Is it possible to implement it in pure Golo?
2- Without DynamicObjects ? This is my shot. Any thoughts are welcomed!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module g0l0.patterns.creationnal.Singleton | |
local function _instance = -> null | |
local function _init = -> DynamicObject(): | |
testing(|this| -> println(this + "doing some stuff")) | |
function MyObject = { | |
if _instance() is null { | |
let instance = _init() | |
^_instance = -> instance | |
} | |
return _instance() | |
} | |
function main = |args| { | |
var instance1 = MyObject() | |
var instance2 = MyObject() | |
assert (instance1 == instance2) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What about this