Class variable

From GNUstepWiki

The Objective-C dialect which is implemented by the GNU Compiler Collection (gcc) does not explicitly support the concept, widely used in some other object-oriented languages, of class variables.

Class variables are shared values or properties of a specific class. This is useful when encapsulating more complex class and instance behaviour which requires the class to keep track, say of numbers of instances created or other more complex behaviours.

A way of implementing class variables is to declare static variables in the class's implementation section, and define class accessor methods if the values need to be changed externally. Note that these statics are not true class variables and will not be inherited by subclasses, and will not be visible outside of the source file's scope.

One can make use of the +initialize method to have class variables initialised when their class is loaded into the runtime.

Compare with the concept of an instance variable.