Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!satisfied.apocalypse.org!news.mathworks.com!uunet!psinntp!isc-newsserver!winesap.rc.rit.edu!user
From: semrc@rc.rit.edu (Sigrid E. Mortensen)
Subject: Class Instance Variables?
Message-ID: <semrc-1503951649030001@winesap.rc.rit.edu>
Sender: news@ultb.isc.rit.edu (USENET News System)
Nntp-Posting-Host: winesap.rc.rit.edu
Organization: RIT Research Corporation
Date: Wed, 15 Mar 1995 21:46:23 GMT
Lines: 55

Hi All!

  A while ago (more than a year, I believe) there was an article in one of
the Smalltalk rags (Smalltalk Report or Scoop, probably) about creating 
class-instance variables in Digitalk Smalltalk.  The article included code.
Well, I've just run into a case where I *really* need a class-instance variable,
and I can't find the article.

  Can anyone point me to the article or, better yet, email me (or post, if \
there's general interest) the code segment that allows one to add class-instance
variables to Smalltalk/V?

  **********

  For those who don't know, a class-instance variable provides the benefit of 
allowing a class to hold onto a single object accessible by all its instances 
(and by the class methods), but allows each subclass of the class who defines
the class-instance variable to place a different value into that variable.  

  Alternatively, with only class variables, the scenario is this: if a 
superclass A has subclasses B and C, A can define a *class* variable AClassVar 
and A, B, and C (and all their instances) will all have access to that variable.
But AClassVar has only one value for all these objects; if it changes in class 
B, it also changes in A and C.  If B and C knew that they each wanted some 
*different* value, they would have to add other class variables (BClassVar and 
CClassVar, respectively).  In addition, they would still inherit AClassVar but 
would ignore it.  When accessing their ClassVar, A would access AClassVar, B 
would access BClassVar, and C would access CClassVar.  This is a shame, since 
AClassVar, BClassVar and CClassVar all serve the same function and only differ 
in value.  The longer your inheritance tree, the more bogus class variables you 
have hanging around unused, and the more unique methods you have to access the 
correct class variable.  Furthermore, (as is true in my case), if you decide to 
modify the classes in a hierarchy where there were no class variables 
originally, it means you have to modify *all* the class definitions in order to 
get a unique variable for each subclass.  Ideally, I'd like to modify only the 
superclass.

  This is a subtle concept, one I didn't grasp until it smacked me in the face. 
When I first heard about class-instance variables, I couldn't imagine how, when 
or why I would ever use them.  Now I see a screaming need for them!

  ***********

  Thanks to anyone who can help!  :-)

  -- Sigrid.

-- 
|=|===============|============================|=|=================|=
|||  Sigrid E.   ||| RIT Research Corporation  |||     phone:     |||
|||  Mortensen   ||| Software Systems Division ||| (716) 475-6761 |||
||| Sr. Computer ||| 75 High Power Road        |||      fax:      |||
|||  Scientist   ||| Rochester, NY 14623       ||| (716) 475-2361 |||
|||              |||  semrc@rc.rit.edu         |||                |||
|||==============|=|============================|=================|=|
