Path: utzoo!utgpu!utstat!jarvis.csri.toronto.edu!mailrus!wuarchive!decwrl!sgi!thant@horus.esd.sgi.com From: thant@horus.esd.sgi.com (Thant Tessman) Newsgroups: comp.object Subject: Re: Understanding the Object-Oriented Life-Cycle Message-ID: <44454@sgi.sgi.com> Date: 10 Nov 89 19:37:14 GMT References: <5026@internal.Apple.COM> <315@shrike.AUSTIN.LOCKHEED.COM> <654@nastar.UUCP> Sender: thant@horus.esd.sgi.com Organization: Silicon Graphics, Inc., Mountain View, CA Lines: 52 In article <654@nastar.UUCP>, joel@nastar.UUCP (Joel Rives) writes: > >aihaug@AUSTIN.LOCKHEED.COM (Daniel A Haug) (aihaug@AUSTIN.LOCKHEED.COM, <315@shrike.AUSTIN.LOCKHEED.COM>): > >By far (IMHO), the largest advantage to this is in code extensibility, > >or reusability. It is so incredibly useful to define an algorithm > >that doesn't care about the types on which it operates. For example, > >I need only implement a priority queue ADT once. The algorithm is the > >same, but the types can be whatever. As result, I only need to write > >one QUEUE and DEQUE procedure that don't depend on any typing. Then, > >every object that is passed into the queue would need to support > >some sort of comparison method that QUEUE would call to determine > >proper placement. > > Perhaps, i am misunderstanding the point you are making here. It is not at > all difficult to code a QUEUE object in C++ that will accept a generic > reference upon which to operate. A new instantiation of this QUEUE object > could be passed a comparison function when created that would be specific > to the data type being queued. Actually, i can think of a couple of different > ways to approach this problem --largely asthetic in their differences. As in > the above example, the algorithm need be coded only once. > > Joel I am just catching the beginning of this thread so pardon my ignorance if this has already been hashed out. I think the first poster is refering to a rather large hole in C++ that hopefully will be plugged by the implementation of parameterized types. Yes, you can implement generic lists and queues in C++ that don't care what they contain, but the implementation is either not type safe, or faked using macros. (See _Programming in C++_ by Dewhurst and Stark for an interesting way to use macros to create generic container classes.) Another trick I (and probably many others) use is to inherit link-listability, (or queueability) from a base class and then make the iterator function (e.g. 'next' or '++') a virtual and overload it to make it return the correct type. This solution is easy if you know the things will only be in one list at a time, and "possible" :-) if the things need to be in multiple lists or queues at a time. Unfortunately, these are all 'tricks' and not C++ proper. Even Stroustrup acknowledges 'parameterized types' as an aspect of Object-Oriented Programming that is orthogonal to 'inheritance,' 'data abstraction,' etc. thant P.S. I do think that C++ is truely a bitchin' language and wouldn't use anything else. -- There are 336 dimples on the standard golf ball.