Singleton: Difference between revisions
Content added Content deleted
m (omit icon) |
m (→{{header|PureBasic}}: update with alternative version) |
||
Line 863: | Line 863: | ||
This will work as long as all functors are linked with <code>import</code> statements. If you use multiple calls to <code>Module.link</code> instead, you will get multiple instances of the "Singleton". |
This will work as long as all functors are linked with <code>import</code> statements. If you use multiple calls to <code>Module.link</code> instead, you will get multiple instances of the "Singleton". |
||
=={{header|PureBasic}}== |
=={{header|PureBasic}}== |
||
===Native version=== |
|||
Thread safe version. |
Thread safe version. |
||
<lang PureBasic>Global SingletonSemaphore=CreateSemaphore(1) |
<lang PureBasic>Global SingletonSemaphore=CreateSemaphore(1) |
||
Line 912: | Line 913: | ||
Data.i @OO_Destroy() |
Data.i @OO_Destroy() |
||
EndDataSection</lang> |
EndDataSection</lang> |
||
===Simple OOP extension=== |
|||
Using the open-source precompiler [http://www.development-lounge.de/viewtopic.php?t=5915 SimpleOOP]. |
|||
<lang PureBasic>Singleton Class Demo |
|||
BeginPrivate |
|||
Name$ |
|||
X.i |
|||
EndPrivate |
|||
Public Method Init(Name$) |
|||
This\Name$ = Name$ |
|||
EndMethod |
|||
Public Method GetX() |
|||
MethodReturn This\X |
|||
EndMethod |
|||
Public Method SetX(n) |
|||
This\X = n |
|||
EndMethod |
|||
Public Method Hello() |
|||
MessageRequester("Hello!", "I'm "+This\Name$) |
|||
EndMethod |
|||
EndClass</lang> |
|||
=={{header|Ruby}}== |
=={{header|Ruby}}== |