Singleton: Difference between revisions

no edit summary
No edit summary
Line 732:
 
static singleton = new Singleton();</syntaxhighlight>
 
=={{header|EMal}}==
<syntaxhighlight lang="emal">
type Singleton
model
text sample
fun speak = void by block do writeLine("I'm a singleton") end
end
Singleton instance
fun getInstance = Singleton by block
if instance == null do instance = Singleton() end
return instance
end
type SomeOtherType
Singleton s1 = Singleton.getInstance()
s1.sample = "Hello"
Singleton s2 = Singleton.getInstance()
s2.sample.append(", World!")
writeLine(s1 + " and " + s2 + " are the same object: " + (s1 == s2) + ", " + s2.sample)
s1.speak() # call instance method
</syntaxhighlight>
{{out}}
<pre>
§(0x02bf8098) and §(0x02bf8098) are the same object: ⊤, Hello, World!
I'm a singleton
</pre>
 
=={{header|Epoxy}}==
214

edits