[Pharo-users] Traits for class methods?
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?
>> Yes it is possible.
> Thanks for your encouragement!
> I ended up trying exactly that example, and it works just fine:
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