Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!uwm.edu!ogicse!orstcs!fog.CS.ORST.EDU!budd From: budd@fog.CS.ORST.EDU (Tim Budd) Newsgroups: comp.lang.c++ Subject: Re: How to define a List class Message-ID: <1991Jun11.155643.13669@lynx.CS.ORST.EDU> Date: 11 Jun 91 15:56:43 GMT References: <350001@hpgnd.grenoble.hp.com> <28539115.4D91@tct.com> Sender: @lynx.CS.ORST.EDU Organization: Computer Science Department, Oregon State Univ. Lines: 31 Nntp-Posting-Host: fog.cs.orst.edu In article <28539115.4D91@tct.com> chip@tct.com (Chip Salzenberg) writes: > 1. Templates (sometimes implemented with the preprocessor) almost > always result in some duplicate code. > > 2. Brute-force downcasting completely trashes type safety. > > 3. Virtual downcast functions require modifying the base class > for each new derivation. > >There is no magic bullet. Choose your poison and make it work. I think these opinions are common, but misplaced. I used to hold some of them myself. Actually I do agree with (1), and I usually avoid templates when I can for just this reason. And if I accept ``Brute-force'' then I guess I agree with 2. What these do NOT imply, however, it that it is impossible to generate data structure classes that have the property that: a) data structures holding different types of objects can share the same methods (that is, new code is not created for every new type of object you hold in your container) b) this is achived with complete type-safety. As evidence (and I don't want to sound like I'm tooting my own horn here, I certain others have made the same observations, only I don't have the information to point to them) I would point to the generic data structure classes I have written. These, and a Latex description, can be obtained by sending mail to ``oopintro@cs.orst.edu'' with subject line ``Generic''. --tim budd, budd@cs.orst.edu