Aha, now I understand your question. >From what I remember #initialize might only be send to classes if they contain an explicit initialize method, but I might remember wrongly.
Cheers, Andrei On Wed, Apr 29, 2015 at 3:08 PM, Jan Blizničenko <blizn...@fit.cvut.cz> wrote: > Thank you both for reply. Unfortunately, it seems I didn't describe my goal > well. > > I want both (all) classes to have separate variables, not shared among > subclasses, but still initialized on class side, not instance side. So I > want those variables to be class-side variables, my problem is with their > initialization. I have a tree of classes, top class (superclass of the > rest) > should have class-side variable initialized as empty collection, and almost > all it's subclasses to have, by default, also an empty colletion. But there > will be few classes in this tree, whose collections should contain > something. > > So to return to my previous example... I want SomeClass class-side variable > "SomeCollection" to contain OrderedCollection()... SubClass along with many > more subclasses to also contain OrderedCollection... but also to have a > SpecificSubClass, whose class-side variable "SomeCollection" will contain > OrderedCollection(something, somethingElse...). > > Jan > > > Sean P. DeNigris wrote > > What you created is a class-side instance variable, which is private to > > just that class. What you want is a class variable, which is shared by > all > > subclasses and instances. You declare it in the class definition with > > #classVariableNames:. There is a very nice explanation of these basic > (but > > confusing!) concepts in the "Pharo By Example" book. > > > Andrei Chis wrote > > Hi, > > > > SomeClass and SubClass are two different objects. > > Based on your setup, if you do not call any initialize method, initially > > calling both "SomeClass isOk" and "SubClass isOk" should return nil. > > > > Running "SomeClass initialize" initializes only the SomeClass object. So > > now "SomeClass isOk" returns true and "SubClass isOk" returns nil, as > its > > another object that has not been initialized. > > You get the same behaviour if you first call "SubClass initialize". > > Now "SomeClass > > isOk" returns nil because you did not initialize the SomeClass object, > > but > > the SubClass. > > > > Even if you add initialize in the SubClass class and call it first > > "SomeClass > > isOk" will still return false. > > SomeClass and SubClass are just two different objects of types SomeClass > > class and SubClass class. It's the same behaviour that you get when you > > create two instances of these classes. Just because you create an > instance > > of the type SubClass and call super initialize, > > it doesn't mean that another instance of SomeClass will be initialized. > > > > Hope this makes sense/answers your question. > > > > Cheers, > > Andrei > > > > > > -- > View this message in context: > http://forum.world.st/class-initialization-and-class-side-variables-tp4822869p4822886.html > Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com. > >