On Thu, Jan 19, 2017 at 3:51 PM, Siemen Baader <siemenbaa...@gmail.com>
wrote:

>
> On Thu, Jan 19, 2017 at 11:33 AM, Cyril Ferlicot D. <
> cyril.ferli...@gmail.com> wrote:
>
>>
>> You just need a class variable #UniqueInstance and those methods:
>>
>> current
>>     "Can also be named #default or #instance"
>>         ^ UniqueInstance
>>                 ifNil: [ UniqueInstance := self basicNew; initialize;
>> yourself ]
>>
>
Actually this should have been: (no `;` between basicNew and initialize).

^ currentInstance
ifNil: [ currentInstance := self basicNew
initialize;
yourself ]

This is not a problem. But it illustrates that this would be nice to have
it unit tested separately and mixed in with a trait/mixin to avoid the risk
of manual errors in what in the end is an already solved problem - if one
wants singletons, of course.

:)

Siemen

>
> Wouldn't a class instance variable be better? I want new singletons for
> every subclass. http://rmod-pharo-mooc.lille.inria.fr/MOOC/Slides/Week3/
> C019-W3S03-Basic-Variables.pdf
>
> I would also have used super new, why BasicNew? But my wish to create
> subclasses seems to answer that already.
>
> Thanks for your find-grained example, Cyril!
>
> Siemen
>

Reply via email to