Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!pdn!tct!chip From: chip@tct.com (Chip Salzenberg) Newsgroups: comp.lang.c++ Subject: Re: About Lists and things... Message-ID: <28692A4A.59B7@tct.com> Date: 26 Jun 91 23:59:06 GMT References: <2865E7A8.179A@tct.com> <19131@prometheus.megatest.UUCP> Organization: TC Telemanagement, Clearwater, FL Lines: 29 According to djones@megatest.UUCP (Dave Jones): >> ... Never design code that requires downcasts. >> Or, in other words: if the static type is important, why worry >> about regaining it? Don't lose it in the first place. > >Something tells me this has all been hashed over previously. The "static >type" was not "lost" in the first place. It did not exist in the first place. 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? -- Chip Salzenberg at Teltronics/TCT , "I want to mention that my opinions whether real or not are MY opinions." -- the inevitable William "Billy" Steinmetz