Difference between revisions of "Class variable"

From GNUstepWiki
Jump to navigation Jump to search
(Description of class variable analog)
 
(Added to category Objective-C)
 
(One intermediate revision by one other user not shown)
Line 3: Line 3:
 
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.
 
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.
+
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]].
+
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]].
 +
 
 +
 
 +
[[Category:Objective-C]]

Latest revision as of 09:45, 21 June 2006

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.