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