This post originated from an RSS feed registered with Agile Buzz
by James Robertson.
Original Post: Class what?
Feed Title: David Buck - Blog
Feed URL: http://www.cincomsmalltalk.com/rssBlog/buck-rss.xml
Feed Description: Smalltalk can do that
The terms "class variables" and "class methods" seem to be widely mis-understood and, hence, misused. You can see this even in professional educational materials. Much of this material seems to use the term "class method" to mean "a method defined within a class" and "class variable" to mean "a variable defined within a class".
The problem is that these terms come from the Smalltalk world and are features found in Smalltalk but don't have equivalents in most other object oriented languages. In Smalltalk, a class method is a method that applies to a class. For example, an instance of Point responds to x, y, dot: and so forth. These are instance methods. The Class Point responds to x:y: to create an instance. This is a class method. The distinction between class methods and instance methods is only made for the sake of the browser - the underlying object oriented mechanisms don't distinguish.
In Smalltalk, a class variable is a single variable whose value is directly visible to all instance methods and class methods of that class as well as from all instance methods and class methods of all subclasses.
The closest thing that C++, Java, and C# have is class static variables and static methods. These aren't quite the same thing as in Smalltalk, but they're very similar. I've seen cases, however, where the term "class variables" was used instead of "instance variables" and the term "class methods" was used instead of "instance methods". It sure gets confusing.