Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!psuvax1!psuvm!cunyvm!nyser!rodan!pwasilko From: pwasilko@rodan.acs.syr.edu (Wasilko) Newsgroups: comp.object Subject: Re: Understanding the Object-Oriented Life-Cycle Message-ID: <1303@rodan.acs.syr.edu> Date: 11 Nov 89 01:56:53 GMT References: <5026@internal.Apple.COM> <315@shrike.AUSTIN.LOCKHEED.COM> <654@nastar.UUCP> <317@shrike.AUSTIN.LOCKHEED.COM> Reply-To: pwasilko@rodan.acs.syr.edu (Wasilko) Organization: Syracuse University, Syracuse, NY Lines: 60 Newsgroups: comp.object Subject: Re: Understanding the Object-Oriented Life-Cycle Summary: Expires: References: <5026@internal.Apple.COM> <315@shrike.AUSTIN.LOCKHEED.COM> <654@nastar.UUCP> <317@shrike.AUSTIN.LOCKHEED.COM> Sender: Reply-To: pwasilko@rodan.acs.syr.edu (Wasilko) Followup-To: Distribution: Organization: Syracuse University, Syracuse, NY Keywords: In article <317@shrike.AUSTIN.LOCKHEED.COM> aihaug@AUSTIN.LOCKHEED.COM (Daniel A Haug) writes: >In article <654@nastar.UUCP>, joel@nastar.UUCP (Joel Rives) writes: >> 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 > >For many of our particular applications, this is overly restrictive. >I may very well want a single queue to hold objects of vastly different >types. Perhaps I'm wrong (and often am ;-), but I don't see how to >accomplish this in a statically typed language. > >dan haug >-- >Internet: haug@austin.lockheed.com >UUCP: ut-emx!lad-shrike!aihaug In Object Pascal I achieve the generic ADT effect by creating a single base- class called anObject with special clone, free, and key methods. The clone method duplicates the object and is overridden by each subclass to also copy any objects stored in them. Each object in the class anObject also holds a referenceCount variable that I use with the free method for automatic garbage collection. Ie. in any arbitrarily complex strucure each time I add an object I increment the referenceCount and when I remove an object I call free which will Dispose of the object only if the referenceCount - 1 is zero, otherwise it decrements the referenceCount. To deal with cyclic structures, each object has a marked flag that is set by free, as free trys to delete subobjects it checks each to see if it is marked. If it is it just decrements that objects referenceCount and detaches it from the structure. ADT all take items of class anObject and call Key for any positional comparisons. For every subclass Key is overridden to produce a sensible string value. Thus class anInteger sets Key to the text representation of the actual number. This aproach is far from elegant and requires the clone, free, and key methods to be overriden for all subclasses, but it does let me work with generic ADT's that I need only define once. If you have any better aproaches for Object Pascal please feel free to let me know... Peter J. Wasilko | I'm not stupid, I'm not expendable, SU Law '91 | and I'm not going --- Avon JWasilko@Sunrise.Acs.Syr.Edu |