Hi Folks.
I needed an object with only one instance so I whipped up the ol' Singleton class. It's nothing special, but I thought you might like it too, so here it is...
---==> Chris
PS> [For Newbies...]
Singletons are classes that can only have a single instance of themselves. This is a fairly common situation in software engineering. I often use singletons to represent the single doorway to my database (e.g. DBManager).
To make use of Singleton, simply create a subclass of it. You can access the single instance of your new class by calling its class method "current" (Singleton will not allow you to create new instances of itself via Singleton class>>new).
For example:
DBManager current saveSomeStuff: stuffToSave.
Enjoy!
<<Singleton.cs>>
Content-Type: application/octet-stream; name="Singleton.cs" Content-Disposition: attachment; filename="Singleton.cs"
Attachment converted: Anon:Singleton.cs (????/----) (000098C8)
----- Original Message ----- From: Norton, Chris chrisn@Kronos.com To: Squeak (E-mail) squeak@cs.uiuc.edu Sent: Friday, April 30, 1999 7:14 PM Subject: [ENH] Singleton class
Hi Folks.
I needed an object with only one instance so I whipped up the ol'
Singleton
class. It's nothing special, but I thought you might like it too, so here it is...
---==> Chris
PS> [For Newbies...]
Singletons are classes that can only have a single instance of themselves. This is a fairly common situation in software engineering. I often use singletons to represent the single doorway to my database (e.g.
DBManager).
To make use of Singleton, simply create a subclass of it. You can access the single instance of your new class by calling its class method
"current"
How about class method #only?
(Singleton will not allow you to create new instances of itself via Singleton class>>new).
Shaping
squeak-dev@lists.squeakfoundation.org