Article View: comp.lang.objective-c
Article #123Re: Requirements for Class Variables for Objective-C
From: moose
Date: Wed, 17 Oct 1990 18:44
Date: Wed, 17 Oct 1990 18:44
68 lines
2541 bytes
2541 bytes
In article <10777@pt.cs.cmu.edu> dandb@k.gp.cs.cmu.edu (Dean Rubine) writes:
[let's leave these choices up for all future posts]
The choices:
#1 -- each subclass has its own copy of its parent's class variables
#2 -- all subclasses share a single copy of their parent's class variables
>
> As I read Mr. Rutman's reasoning, given choice #2, all I'd have to do to
>associate an event handler with every subclass of View is declare a variable
>(class or static) in EVERY subclass, and provide appropriate methods in EVERY
>subclass. Yeech. Note that I'd likely be repeating the same code in every
>subclass - this seems contrary to the object-oriented paradigm, in which
>inheritance is supposed to be used to avoid such of repetition of code. This
>problem doesn't come up with class variables of kind #1.
A bit of code is going to follow.
int myGlobal;
+ saveMyGlobal:(int)number
{
myGlobal = number;
return self;
}
+ (int)getMyGlobal
{
return myGlobal;
}
now, all references to myGlobal are through these lovely factory methods.
(Instance methods would work fine, but who cares :->)
Subclass now.
We want to override myGlobal with
int myOwnGlobal;
We override saveMyGlobal and getMyGlobal with
+ saveMyGlobal:(int)number
{
myOwnGlobal = number;
return self;
}
+ (int)getMyGlobal {return myOwnGlobal;}
We could even go so far as to have something like
+ saveMyGlobal:(int)number
{
myGlobal -= myOwnGlobal; //to remove the old value
myGlobal += number; //keep a total for all subclasses
myOwnGlobal = number;
return self;
}
Now, show me how to do that in #1, a case where I actually want the subclass
to have its own copy of the variable and a copy of the superclasses variable.
--
Michael Rutman | moose@svc.portal.com
Cubist | makes me a NeXT programmer
Software Ventures | That's in Berkeley
smile, you're on standard disclaimer | <fill in with cute saying>
Technical Details
Message-ID:
<1990Oct17.184431.14195@svc.portal.com>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!julius.cs.uiuc.edu!apple!portal!sv!mooseReferences:
<5638@stpstn.UUCP> <270A66D0.14263@ics.uci.edu> <kenneth.655324438@exklusiv> <GREGOR.90Oct14231438@spade.parc.xerox.com> <1990Oct15.185718.8342@svc.portal.com> <10777@pt.cs.cmu.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!julius.cs.uiuc.edu!apple!portal!sv!moose From: moose@svc.portal.com Newsgroups: comp.lang.objective-c Subject: Re: Requirements for Class Variables for Objective-C Message-ID: <1990Oct17.184431.14195@svc.portal.com> Date: 17 Oct 90 18:44:31 GMT References: <5638@stpstn.UUCP> <270A66D0.14263@ics.uci.edu> <kenneth.655324438@exklusiv> <GREGOR.90Oct14231438@spade.parc.xerox.com> <1990Oct15.185718.8342@svc.portal.com> <10777@pt.cs.cmu.edu> Organization: Software Venture Lines: 68