[Pharo-users] Traits for class methods?

Marcus Denker marcus.denker at inria.fr
Wed Feb 13 07:02:03 EST 2019

> On 13 Feb 2019, at 12:22, Konrad Hinsen <konrad.hinsen at fastmail.net> wrote:
> On 11/02/2019 17:18, Cyril Ferlicot wrote:
>> A quick question: is it possible to use traits to define class methods?
>>> For example, could the popular singleton pattern consisting of the
>>> three class methods #uniqueInstance, #new, and #reset plus the instance
>>> variable uniqueInstance be packaged as a trait?
>> Hi,
>> Yes it is possible.
> Thanks for your encouragement!
> I ended up trying exactly that example, and it works just fine:
>     https://github.com/khinsen/SingletonTrait

It is amazing how much better this feels now that Traits can define state, too… (compared to before where it was just methods).


I would even want to have (and use) a Trait like that in the system by default.


More information about the Pharo-users mailing list