Path: utzoo!attcan!uunet!ginosko!ctrsol!cica!gatech!hubcap!billwolf%hazel.cs.clemson.edu From: billwolf%hazel.cs.clemson.edu@hubcap.clemson.edu (William Thomas Wolfe, 2847 ) Newsgroups: comp.sw.components Subject: Re: List ADT example Message-ID: <6555@hubcap.clemson.edu> Date: 23 Sep 89 21:06:02 GMT References: <902@scaup.cl.cam.ac.uk> Sender: news@hubcap.clemson.edu Reply-To: billwolf%hazel.cs.clemson.edu@hubcap.clemson.edu Lines: 51 From scc@cl.cam.ac.uk (Stephen Crawley): >> OK, first let me clarify my position. The primary use for pointers >> is simply to implement abstract data types -- lists, trees, graphs, etc.; >> by shielding the user from the details of implementation, we can keep >> the user from having to worry about manipulating pointers. > > Frankly, I can't see how this is possible. Suppose I have an ADT 'A' > that has a generator operation NEW and a destructor function DISPOSE. > Suppose I want a generic ADT LIST[t: type] that can be used in the > following way. -- create X and Y, two instances of type A; -- create a list L, containing objects of type A -- loop -- append X to the list L -- append a constant object of type A to the list L -- append X to the list L again -- assign the head of list L to the variable Y -- end loop; > The generation of instances of A must be under the control of the > application and assignment of A must be handled. I must be able to > put an A instance into a list any number of times. > > How do I implement the LIST ADT so that it invokes the A$DISPOSE > operation at the right time? When is the right time? What happens > if I want to put an instance of A into 2 LIST's at the same time? When you make your instantiation of the list type for objects of type A, you must fulfill the instantiation requirements. This will normally include supplying assignment and destruction procedures for objects of type A. If you send an object into the list, the assignment procedure will be used to create a resident copy. If you direct the removal of an object from the list, the destruction procedure will be used to destroy it. (See Booch, "Software Components with Ada") If the type A was an object, then the objects will be created and destroyed as appropriate. If the type A was a pointer, then the pointers will be created and destroyed as appropriate. It all depends on what the user supplies for type A and how the user directs that the assignment and destruction operations for type A are to be performed. The "generic" part means that the implementor proceeds with respect to an arbitrary, user-supplied type which will have the specific operations required of it, without worrying about what that type is or how the operations over it are to be implemented; these are decisions which the user has agreed to make in exchange for the ADT's services. Bill Wolfe, wtwolfe@hubcap.clemson.edu