Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!samsung!uunet!mcsun!inesc!minerva!fmhv From: fmhv@minerva.inesc.pt (Fernando Manuel Vasconcelos) Newsgroups: comp.lang.c++ Subject: Re: About Lists and things... Message-ID: <1991Jun27.095856.2@minerva.inesc.pt> Date: 27 Jun 91 10:00:52 GMT References: <2865E7A8.179A@tct.com> <19131@prometheus.megatest.UUCP> <28692A4A.59B7@tct.com> Sender: news@inesc.UUCP Organization: INESC, Lisboa, Portugal Lines: 41 Nntp-Posting-Host: minerva.inesc.pt In article <28692A4A.59B7@tct.com> chip@tct.com (Chip Salzenberg) writes: >By "static type" I mean "compile-time type". Perhaps an example will >clarify my point. > >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. > >Of course, that change 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. > >Clearer now? 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 . Only my two cents ... -- Fernando Manuel Hourtiguet de Vasconcelos INESC - Instituto de Engenharia de fmhv@inesc.inesc.pt Sistemas e Computadores mcsun!inesc!fmhv@uunet.uu.net Rua Alves Redol No 9, sala 208 Tel: +351(1)545150 Ext. 216 Apartado 10105