RosettaCodeData/Task/Singleton/EMal/singleton.emal

18 lines
540 B
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
type Singleton
model
text greeting
2026-04-30 12:34:36 -04:00
fun speak ← void by block do writeLine(me.greeting + " I'm a singleton") end
2023-07-01 11:58:00 -04:00
end
Singleton instance
2026-04-30 12:34:36 -04:00
fun getInstance ← Singleton by block
if instance æ null do instance ← Singleton() end
2023-07-01 11:58:00 -04:00
return instance
end
type SomeOtherType
2026-04-30 12:34:36 -04:00
Singleton s1 ← Singleton.getInstance()
s1.greeting ← "Hello"
Singleton s2 ← Singleton.getInstance()
2023-07-01 11:58:00 -04:00
s2.greeting.append(", World!")
2026-04-30 12:34:36 -04:00
writeLine(s1 + " and " + s2 + " are the same object: " + (s1 æ s2) + ", s2: " + s2.greeting)
2023-07-01 11:58:00 -04:00
s1.speak() # call instance method