I just created my own package(MyPackage) and class(MyClass) in pharo, using the System Browser. This is how it looks.
Object subclass: #MyClass
instanceVariableNames: ''
classVariableNames: ''
category: 'MyPackage'
I understand the terms subclass and category, not getting the meaning of the other two terms (instanceVariableNames, classVariableNames).
I have an impression that this question was already asked and answered, but I was not able to find it, probably it was on a mailing list.
Instance variables are just the variables that are personal to an instance, so each instance of the class that you are defining will have it's own set of variables.
Instance variables of the class side. You can define that when you switch to the class side, then you will se a code like this:
MyClass class
instanceVariableNames: ''
In Pharo (and Smalltalks in general) each class is an instance of a meta class. The variables can be accessed by class-side methods, and as there is only a single instance representing class object, there will be only one set of these variables of that instance.
Class variables are the variables defined by classVariableNames: ''
on the instance side template. I like to call them "pool variables", but in fact if you define such variable, all the instances from the hierarchy will be able to access it. Let's say that you have a class A
and it's subclass B
. If you have a "class variable" in A
, you can access the same variable from both instances of A
and B
. It's like having a global variable for a hierarchy. I recommend not to use this type of variables.