Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!fs7.ece.cmu.edu!hudson.lm.com!news.pop.psu.edu!psuvax1!uwm.edu!spool.mu.edu!torn!nott!cunews!dbuck
From: dbuck@superior.carleton.ca (Dave Buck)
Subject: Re: Class variable question
Message-ID: <CzIt5H.MBp@cunews.carleton.ca>
Sender: news@cunews.carleton.ca (News Administrator)
Organization: Carleton University, Ottawa, Canada
References: <199411180114.a31834@ms.maus.de>
Date: Sat, 19 Nov 1994 15:17:41 GMT
Lines: 43

In article <199411180114.a31834@ms.maus.de>,
Carsten Haerle <Carsten_Haerle@ms.maus.de> wrote:
>Could someone explain the following about class variables to me?
>
>I thought that class variable were instance variable of the corresponding meta
>class of a class. This would imply that if I subclass a class A, which has a
>class variable VarA, with a class B, that I could assign different values to
>the VarA variable in the class A and the class B. Instead (at least in the
>Digitalk's implementation), there is only one value. If I assign something to
>VarA in class B, the class variable of class A gets updated too, i.e. there
>seems to be only one class variable for both classes.

This is the standard operation of class variables.  A class variable
is a single variable which is accessible to the class, its instances,
its subclasses, and all of their instances.  It's used like a global
whose scope is limited.  For example, in Smalltalk/V Win32, the class
Pattern has a class variable called WildcardCharacter which contains
the character $*.  All instances of Pattern and all instances of its
subclasses can access this value.

What you want is a class instance variable.  A class instance variable
(as opposed to a class variable) is an instance variable of a class.
Its scope is the same as any other instance variable - it's
accessible to methods of that class (class methods in this case), but
each instance has its own separate variable (i.e., each subclass has a
different variable with the same name).

Class instance variables are a fairly new invention in Smalltalk.  You
can create them in ST/V Win32 or in VW by clicking on the class button
in the browser and adding inst var names in the line shown in the text
window of the browser.


David Buck
dbuck@ccs.carleton.ca

_________________________________
| David K. Buck                 |
| dbuck@ccs.carleton.ca         |
| The Object People             |
|_______________________________|
 

