Singleton: Difference between revisions

m
→‎{{header|PureBasic}}: update with alternative version
m (omit icon)
m (→‎{{header|PureBasic}}: update with alternative version)
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".
=={{header|PureBasic}}==
===Native version===
Thread safe version.
<lang PureBasic>Global SingletonSemaphore=CreateSemaphore(1)
Line 912 ⟶ 913:
Data.i @OO_Destroy()
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}}==
Anonymous user