Singleton: Difference between revisions
Latitude language added
Mercerenies (talk | contribs) (Latitude language added) |
|||
Line 1,210:
#a->switch // b</lang>
=={{header|Latitude}}==
Latitude objects are prototypes, so any new object can be treated as a singleton by simply not cloning it. For added security, one can always override <code>clone</code> to make it clear that the object should not be cloned, but this is generally overkill.
<lang latitude>Singleton ::= Object clone tap {
self id := 0.
self newID := {
self id := self id + 1.
}.
self clone := {
err ArgError clone tap { self message := "Singleton object!". } throw.
}.
}.
println: Singleton newID. ; 1
println: Singleton newID. ; 2
println: Singleton newID. ; 3</lang>
=={{header|Lingo}}==
|