How to use Class variables
Jump to navigation
Jump to search
- I made a video to show the process of dealing with class variables, see here XXXXTODOXXXXX
- Class variables are a good alternative to global variables to store date relative a certain class.
- Suppose we are working no a class
MyClass
and we want to define there two class variablesFooVar1
andFooVar2
. - Class variables are defined in the Class definition area, where there are also instance variables, one line below.
- Class variable name first letter must be in uppercase.
- Class variables are initialized when the Class is learnt by the system, that is, in general or when you run Cuis or when you load the external package that contains the class definition.
- If you want to initialize your class variable when class variables when the class is learnt by the system you must do so in the
MyClass class >> initialize
method. From there you can set the variables asFooVar1 := 123
. - To see the name of class variables in a class use
MyClass classPool
. - Class variables can be modified and red directly only class method accessors.
- Class variables are inherited by subclasses.
- Class variables are fixed for all instances of the class.