Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!rpi!uupsi!sunic!EB.se!kenneth From: kenneth@EB.se (Kenneth Persson) Newsgroups: comp.lang.objective-c Subject: Re: Requirements for Class Variables for Objective-C Keywords: class variables Message-ID: Date: 7 Oct 90 18:33:58 GMT References: <5638@stpstn.UUCP> <270A66D0.14263@ics.uci.edu> Sender: news@EB.se (EB Signal News server) Organization: EB Signal AB, Stockholm, Sweden Lines: 38 I first replied to the author of the original article, but this is the place for discussion: rmyers@ics.uci.edu (Richard E. Myers) writes: >In answer to your first two questions, I believe class variables would >be useful and that case one would be the better system. >>** 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 I would prefer case 2! > I think at run time each subclass should be thought of as distinct >from its parent and thus have it's own variables... Inheritance is just an implementation technique to minimize redundant code. At run time there is no subclasses or superclasses, just objects (and classes that I think of as objects too). If you have class hierarchy (bad example): Picture | \ TextPic GeometricPic you want them to share the same Printer. etc etc. Note that you can simulate class variables with the static mechanism. Since every class is declared in it's own file a static works like a class variable, with the restriction that it's not inherited. If you supply the class with a factory method that return the static you can use it in subclasses too. |+cPrinter| and |+cPrinter: aPrinter|. -- +-------------------------+--------------------------+ | Kenneth Persson | email: kenneth@eb.se | | EB Signal AB, Sweden | voice: +46 8 726 2267 | +-------------------------+--------------------------+