[squeak-dev] Re: singleton?

Claus Kick claus_kick at web.de
Thu Apr 10 18:55:32 UTC 2008


Bert Freudenberg wrote:

>> class-side method:
>> theInstance
>> ^(self allInstances at: 1 ifAbsent: [self new].

> You cannot do this because it might find a PlotMorph in a different  
> world (each project has a world).

What about a Class Method with a Class Variable called Singleton:

singleton

Singleton ifNil:[Singleton := self new. ^Singleton].
^Singleton

Drawback is you have to remember to call MyClass singleton each time you 
want to access the singleton, but well...

Claus




More information about the Squeak-dev mailing list