From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,ecfc0548c2df0d76 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-11-07 02:27:08 PST Path: archiver1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!tar-alcarin.cbb-automation.DE!not-for-mail From: Dmitry A. Kazakov Newsgroups: comp.lang.ada Subject: Re: MI ammunition : linked lists Date: Fri, 07 Nov 2003 11:29:12 +0100 Message-ID: References: NNTP-Posting-Host: tar-alcarin.cbb-automation.de (212.79.194.111) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de 1068200827 48470421 212.79.194.111 (16 [77047]) X-Newsreader: Forte Agent 1.8/32.548 Xref: archiver1.google.com comp.lang.ada:2194 Date: 2003-11-07T11:29:12+01:00 List-Id: On Thu, 6 Nov 2003 16:32:16 -0000, "amado.alves" wrote: >A very common programming task where multiple inheritance (MI) would be handy: implementation of doubly linked lists. > >It is clear that the middle nodes combine the attributes of the first and last nodes. This is where linguistic MI could help: > > type Node is tagged ...; > > type Node_Ptr is access Node'Class; > > type First_Node is new Node with record > Next : Node_Ptr; > end record; > > type Last_Node is new Node with record > Prev : Node_Ptr; > end record; > > type Middle_Node is new First_Node with Last_Node; Well if you want it, it should be sort of: type Node is abstract tagged ...; -- There is no dangling nodes type Node_Ptr is access Node'Class; type First_Node is new Node with private; type First_Node_Ptr is access First_Node'Class; -- Cannot define First_Node without pointers to Last_Node type Last_Node is new Node with private; type Last_Node_Ptr is access Last_Node'Class; type Middle_Node is new First_Node, Last_Node with private; private type First_Node is new Node with record Next : Last_Node_Ptr; -- Only a Last_Node'Class can follow me end record; type Last_Node is new Node with record Prev : First_Node_Ptr; -- Only a First_Node'Class can precede me end record; type Middle_Node is new First_Node, Last_Node with null record; >Of course the alternative is no big deal, syntactically: > > type Middle_Node is new Node with record > Prev : Node_Ptr; > Next : Node_Ptr; > end record; Which is semantically wrong. 1. IF you want to map node precedence to types, then you have to consequently follow this. See above. 2. The alternative is that all nodes are same and thus there is no reason to distinguish them as First / Middle / Last. And as a consequence, they have to be moved into the private part, for they become an implementation detail then. >But, semantically, MI would allow conversions between Middle_Node and any the other two extended types. Whether this would be useful for linked lists remains to be ascertained. I confess I have not implemented them this way yet. I did and I missed MI much, because as I said, the alternative design of Middle_Node is unclean. As a result, time to time the clients HAVE to use casts from Node_Ptr to more specific types. This is BAD. BTW. You will ahve to add "all" to the node access types, if you have many of them. Pool specific access types are tagged-unfriendly in Ada. --- Regards, Dmitry Kazakov www.dmitry-kazakov.de