Singleton: Difference between revisions
Content deleted Content added
No edit summary |
|||
Line 737:
type Singleton
model
text
fun speak = void by block do writeLine(me.greeting + " I'm a singleton") end
end
Singleton instance
Line 747:
type SomeOtherType
Singleton s1 = Singleton.getInstance()
s1.
Singleton s2 = Singleton.getInstance()
s2.
writeLine(s1 + " and " + s2 + " are the same object: " + (s1 == s2) + ", s2: " + s2.
s1.speak() # call instance method
</syntaxhighlight>
{{out}}
<pre>
§(0x02bf8098) and §(0x02bf8098) are the same object: ⊤, s2: Hello, World!
Hello, World! I'm a singleton
</pre>
|