Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!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: <6590@hubcap.clemson.edu> Date: 26 Sep 89 18:41:39 GMT References: <915@scaup.cl.cam.ac.uk> Sender: news@hubcap.clemson.edu Reply-To: billwolf%hazel.cs.clemson.edu@hubcap.clemson.edu Lines: 51 From article <915@scaup.cl.cam.ac.uk>, by scc@cl.cam.ac.uk (Stephen Crawley): > Bill Wolfe writes: >> >> 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") >> > > First objection: I don't want to put a copy of the instance of A into > the list twice. I want to put the SAME instance of A into the list > twice. If A is a mutable type (i.e. has operations that can change > a value) this is a significant semantic difference. Then what you want is a list of pointers, not a list of objects. > Second objection: You do not say how the assign and destruct operations > get invoked when an instance of A returned by the LIST ADT to the > application. The ADT requires the user to supply the operations, and will invoke them when appropriate. When the user requests that something be inserted, the ADT will invoke the assignment procedure to create a copy. When the user requests that something be removed, the ADT will invoke the Destroy procedure to destroy it. If the thing being stored is an object, then the ADT makes and subsequently destroys its copy of that object. If the thing being stored is a pointer, then the ADT makes and subsequently destroys its copy of that pointer. > I can't see how the application is forced to call DESTROY on an A > variable when its declaration scope exits. As mentioned above, the ADT creates and destroys on its own with respect to the stored object. As far as the ADT's destruction goes, the automatic destruction upon scope exit is not a part of Ada 83; it is presently being considered as an Ada 9X revision. This revision will greatly improve the ability to specify and use components which manage their own space. > [Example of an assignment procedure using reference counting] Try writing the assignment procedure without reference counting, since nobody ever does reference counting inside assignment anyway... Bill Wolfe, wtwolfe@hubcap.clemson.edu