Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!think.com!sdd.hp.com!apollo!vinoski From: vinoski@apollo.hp.com (Stephen Vinoski) Newsgroups: comp.lang.c++ Subject: Re: About Lists and things... Message-ID: <1991Jun27.152553.12762@apollo.hp.com> Date: 27 Jun 91 15:25:53 GMT References: <19131@prometheus.megatest.UUCP> <28692A4A.59B7@tct.com> <1991Jun27.095856.2@minerva.inesc.pt> Sender: netnews@apollo.hp.com (USENET posting account) Organization: Hewlett-Packard Company, Apollo Division - Chelmsford, MA Lines: 44 Nntp-Posting-Host: zep_e.ch.apollo.hp.com In article <1991Jun27.095856.2@minerva.inesc.pt> fmhv@minerva.inesc.pt (Fernando Manuel Vasconcelos) writes: >In article <28692A4A.59B7@tct.com> chip@tct.com (Chip Salzenberg) writes: >>If you put a Circle into a ShapeList, you lose the Circle's >>compile-time type, because ShapeList.first() returns |Shape*|. >>Suppose that you decide to call a Circle-specific function on a Circle >>stored in a ShapeList. Some would cast the |Shape*| to a |Circle*| >>and carry on. My coding practice would require you to replace the >>ShapeList with a CircleList. > >I may be missing the point, however consider two objections to your proposal: > >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 ... ) > >2. A conceptual one: That means the interface of a base class depends on the >interface of the derived classes. Using your example it is normal that a >circle should know to answer it's radius. If I keep all my graphical >objects in a list of shapes* , I'll have to add a getRadius message to >the Shape class, only because a circle knows what that means ... But a GENERAL >shape doesn't . The answer to your objections is that you shouldn't be designing your software so that you lose the "compile-time type" as Chip calls it. If you're putting a Circle onto a ShapeList, it effectively becomes a Shape. In a sense, it is no longer a Circle (though the use of virtual functions allow it to keep some of its "circle-ness"). Its interface becomes a Shape interface, not a Circle interface. If you need a Circle interface, design your software so that you always put your Circle onto a CircleList. Only put your Circles onto ShapeLists when you're dealing with Shapes. I agree with Chip 300%. -steve | Steve Vinoski (508)256-0176 x5904 | Internet: vinoski@apollo.hp.com | | HP Apollo Division, Chelmsford, MA 01824 | UUCP: ...!apollo!vinoski | -- | Steve Vinoski (508)256-0176 x5904 | Internet: vinoski@apollo.hp.com | | HP Apollo Division, Chelmsford, MA 01824 | UUCP: ...!apollo!vinoski |