[ENH] Singleton class

Norton, Chris chrisn at Kronos.com
Sat May 1 00:14:04 UTC 1999


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)





More information about the Squeak-dev mailing list