Singleton: Difference between revisions

m
{{out}}
m ({{out}})
Line 1:
{{task|Object oriented}}
{{task|Object oriented}}A Global Singleton is a class of which only one instance exists within a program. Any attempt to use non-static members of the class involves performing operations on this one instance.
A Global Singleton is a class of which only one instance exists within a program.
{{task|Object oriented}}A Global Singleton is a class of which only one instance exists within a program. Any attempt to use non-static members of the class involves performing operations on this one instance.
 
=={{header|ActionScript}}==
Line 531 ⟶ 533:
x.wait ; y.wait ; z.wait ;
}</lang>
{{out}}
Sample Output:
<pre>>>Mary come in.
Calling Dealer...
Line 711 ⟶ 713:
}
}</lang>
{{out}}
Output:
<pre>invoking method of a singleton class</pre>
 
Line 1,010 ⟶ 1,012:
</lang>
 
{{out}}
'''output'''
<pre style="height:30ex;overflow:scroll">
main____________:0000000001:@035a8767|-
Line 1,327 ⟶ 1,329:
(dm message2> ()
(prinl "This is method 2 on " This) )</lang>
{{out}}
Output:
<pre>: (message1> '+Singleton)
This is method 1 on +Singleton
Line 1,477 ⟶ 1,479:
 
=={{header|Slate}}==
Clones of Oddball themselves may not be cloned. Methods and slots may still be defined on them:
Methods and slots may still be defined on them:
<lang slate>define: #Singleton &builder: [Oddball clone]</lang>
 
Line 1,513 ⟶ 1,516:
}
}</lang>
Demonstrating in an interactive shell:
<lang tcl>% set a [example new]
::oo::Obj20
Line 1,556 ⟶ 1,559:
 
=={{header|zkl}}==
A class declared static only has one instance, ever. However, a class with the same name & structure could be created in another scope.
However, a class with the same name & structure could be created in another scope.
<lang zkl>class [static] Borg{ var v }
b1 := Borg; b2 := Borg();
Anonymous user