Singleton: Difference between revisions

No edit summary
Line 737:
type Singleton
model
text samplegreeting
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.samplegreeting = "Hello"
Singleton s2 = Singleton.getInstance()
s2.samplegreeting.append(", World!")
writeLine(s1 + " and " + s2 + " are the same object: " + (s1 == s2) + ", s2: " + s2.samplegreeting)
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>
 
218

edits