🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.objective-c
Article #113

Re: Requirements for Class Variables for Objective-C

#113
From: Dean Rubine
Date: Thu, 04 Oct 1990 04:40
41 lines
3024 bytes
    For the simple cases, class variables can be simulated in Objective-C
with static variables declared in the same file that the class is declared.
This is limited in that superclasses or subclasses of the class cannot access
the class variables directly, but instead need to call methods in
defining class.  Actually, from a modularity standpoint, that's probably not
too bad, but it goes against the Objective C philosophy, such as it is.

    For more complicated needs, I think the suggestion that each subclass have
its own copy of its parent's class variables is the correct one, since it's
easy to do the other case (every subclass accessing the same, single copy of
their parent's class variables) with statics or globals.  I came across the
need for class variables when I needed to associate an event-handler object
with every subclass of a given class - with the correct semantics, a single
class variable, in the parent class, would do the job.  

   I solved the problem in the obvious way, with an association list, where I
associated the factory object with the event-handler object.  Actually, I
implemented the general case of property lists, which associate name/property
pairs with arbitrary objects.   Then the property lists' name/property/value
implement class variables as class-object/class-var-name/class-var-value. 
[Alternatively, property lists names can be the variable names and properties
can be class objects; it depends on the implementation as to which is better.] 

   As far as I know, there are no conceptual reasons why class variables
haven't been implemented in Objective-C yet; it just seems that no one has
gotten around to it.  In point of fact, there are already a fixed number of
class variables already stored per class (I'm refering to the fact that
each factory object has an "isa" class variable, a "clsSuper" class variable
which points at the factory object of the superclass, a "clsName" which
is a string, "clsTypes" which describes the type instance variables of the
class, as well as size information of instances, and a dispatch table,
both of which can be considered class variables as well).  All that's needed
is some syntax for adding to this existing structure of class variables on
a per class basis.

-- 
ARPA:       Dean.Rubine@CS.CMU.EDU	
PHONE:	    412-268-2613		[ Free if you call from work ]
US MAIL:    Computer Science Dept / Carnegie Mellon U / Pittsburgh PA 15213
DISCLAIMER: My employer wishes I would stop posting and do some work.
Technical Details
Message-ID: <10652@pt.cs.cmu.edu>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!zephyr.ens.tek.com!uw-beaver!mit-eddie!rutgers!rochester!pt.cs.cmu.edu!k.gp.cs.cmu.edu!dandb
References: <5638@stpstn.UUCP> <270A66D0.14263@ics.uci.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!zephyr.ens.tek.com!uw-beaver!mit-eddie!rutgers!rochester!pt.cs.cmu.edu!k.gp.cs.cmu.edu!dandb
From: dandb@k.gp.cs.cmu.edu (Dean Rubine)
Newsgroups: comp.lang.objective-c
Subject: Re: Requirements for Class Variables for Objective-C
Keywords: class variables
Message-ID: <10652@pt.cs.cmu.edu>
Date: 4 Oct 90 04:40:13 GMT
References: <5638@stpstn.UUCP> <270A66D0.14263@ics.uci.edu>
Organization: Carnegie-Mellon University, CS/RI
Lines: 41