Hi guys, Can anyone please quickly explain to me the difference between (1) an instance variable defined on the class side and (2) a class variable defined on the instance side? Thanks a lot! Cheers, Roberto
A class variable is shared between the class, its subclasses, its instances and its subclasses instances. An instance variable of a class is a regular instance variable (can be accessed only by the object holding it, in this case, the class and its subclasses have all an instance variable with potentially different objects in it). 2015-01-07 17:40 GMT+01:00 Roberto Minelli <roberto.minelli@usi.ch>:
Hi guys,
Can anyone please quickly explain to me the difference between (1) an instance variable defined on the class side and (2) a class variable defined on the instance side?
Thanks a lot!
Cheers, Roberto
Thank you, Clément! We use instance var on class side is to implement singleton, for example. Iâve never used a class var and I am wondering what is a the most common use of such a variable? Cheers, R
On 07 Jan 2015, at 17:57, Clément Bera <bera.clement@gmail.com> wrote:
A class variable is shared between the class, its subclasses, its instances and its subclasses instances.
An instance variable of a class is a regular instance variable (can be accessed only by the object holding it, in this case, the class and its subclasses have all an instance variable with potentially different objects in it).
2015-01-07 17:40 GMT+01:00 Roberto Minelli <roberto.minelli@usi.ch>: Hi guys,
Can anyone please quickly explain to me the difference between (1) an instance variable defined on the class side and (2) a class variable defined on the instance side?
Thanks a lot!
Cheers, Roberto
On 07 Jan 2015, at 14:06, Roberto Minelli <roberto.minelli@usi.ch> wrote:
Thank you, Clément!
We use instance var on class side is to implement singleton, for example. Iâve never used a class var and I am wondering what is a the most common use of such a variable?
Singletons where you have a hierarchy of classes and you want to have just one object for the whole hierarchy. e.g. ThemeIcons, there the singleton was until recently a class instance variable, leading to us having multiple instances of the singleton in the image, one per subclass. Marcus
Thanks a lot Marcus! Indeed I used it also like that once. Cheers, Roberto
On 07 Jan 2015, at 18:13, Marcus Denker <marcus.denker@inria.fr> wrote:
On 07 Jan 2015, at 14:06, Roberto Minelli <roberto.minelli@usi.ch> wrote:
Thank you, Clément!
We use instance var on class side is to implement singleton, for example. Iâve never used a class var and I am wondering what is a the most common use of such a variable?
Singletons where you have a hierarchy of classes and you want to have just one object for the whole hierarchy.
e.g. ThemeIcons, there the singleton was until recently a class instance variable, leading to us having multiple instances of the singleton in the image, one per subclass.
Marcus
may be you can read pharo by example... Le 7/1/15 17:40, Roberto Minelli a écrit :
Hi guys,
Can anyone please quickly explain to me the difference between (1) an instance variable defined on the class side and (2) a class variable defined on the instance side?
Thanks a lot!
Cheers, Roberto
participants (4)
-
Clément Bera -
Marcus Denker -
Roberto Minelli -
stepharo