Class variable

From GNUstepWiki

(Difference between revisions)

Revision as of 14:46, 14 November 2005

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.

Compare with the concept of an Instance variable.