Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!ccu.umanitoba.ca!herald.usask.ca!alberta!brazeau.ucs.ualberta.ca!unixg.ubc.ca!ubc-cs!uw-beaver!zephyr.ens.tek.com!uunet!pdn!myrddin!tct!chip From: chip@tct.com (Chip Salzenberg) Newsgroups: comp.lang.c++ Subject: Re: About Lists and things... Message-ID: <286B8088.54A4@tct.com> Date: 28 Jun 91 18:31:35 GMT References: <19131@prometheus.megatest.UUCP> <28692A4A.59B7@tct.com> <1991Jun27.095856.2@minerva.inesc.pt> Organization: TC Telemanagement, Clearwater, FL Lines: 41 According to fmhv@minerva.inesc.pt (Fernando Manuel Vasconcelos): >In article <28692A4A.59B7@tct.com> chip@tct.com (Chip Salzenberg) writes: > >>Of course, [a CircleList] may not be practical, perhaps because there are >>other non-Circle objects in the ShapeList. If so, congratulations! >>You have just discovered that the function in question is actually a >>Shape function in disguise. You should therefore add it to the Shape >>interface, presumably as a new virtual function. > >1. A pratical one: You may not be able to change shape.h because it belongs >to a library which you have only in binary ( of course you have the .h's but >you can't change them ... ) The best way to solve this problem is to avoid it: get source code. My personal choice is never to derive from a class unless I have source code for it. Instead, I compose (create new classes with the binary-only classes as members). >2. A conceptual one: That means the interface of a base class depends on the >interface of the derived classes. My policy simply acknowledges this obvious fact: as a programmer gains experience in deriving from class X, her insight into the nature of class X deepens. Such insight can lead her to change class X in accord with her newly gained experience. To return to Shapes and Circles: A ShapeList can contain anything derived from Shape, including classes not yet invented at compile time. Any code that works with a ShapeList of necessity deals only with the Shape interface. Therefore, for you to perform a particular operation on the elements of a ShapeList, it is apparent that the operation in question must (or should) be a part of the Shape interface. If such is not the case, then the code needs to be recast so the operation in question is not applied to a ShapeList, but rather to a more specialized collection such as a CircleList. -- Chip Salzenberg at Teltronics/TCT , "I want to mention that my opinions whether real or not are MY opinions." -- the inevitable William "Billy" Steinmetz