Class variable

From GNUstepWiki

(Difference between revisions)
Revision as of 14:46, 14 November 2005
Comrade (Talk | contribs)
Description of class variable analog
← Previous diff
Revision as of 03:33, 22 November 2005
Quineska (Talk | contribs)

Next diff →
Line 4: Line 4:
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. 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]]. Compare with the concept of an [[Instance variable]].

Revision as of 03:33, 22 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.

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.