comp.lang.ada
 help / color / mirror / Atom feed
From: Dmitry A. Kazakov <mailbox@dmitry-kazakov.de>
Subject: Re: MI ammunition : linked lists
Date: Fri, 07 Nov 2003 11:29:12 +0100
Date: 2003-11-07T11:29:12+01:00	[thread overview]
Message-ID: <bgrmqvs8ocqnrpt000q3t7ubnq1f8j20kd@4ax.com> (raw)
In-Reply-To: mailman.293.1068136383.25614.comp.lang.ada@ada-france.org

On Thu, 6 Nov 2003 16:32:16 -0000, "amado.alves"
<amado.alves@netcabo.pt> 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



  parent reply	other threads:[~2003-11-07 10:29 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-11-06 16:32 MI ammunition : linked lists amado.alves
2003-11-06 16:46 ` Stephen Leake
2003-11-06 17:15 ` Frank J. Lhota
2003-11-08 10:27   ` Dmitry A. Kazakov
2003-11-06 17:16 ` Jean-Pierre Rosen
2003-11-06 18:15   ` Wes Groleau
2003-11-06 21:03   ` Simon Wright
2003-11-07 10:39     ` Dmitry A. Kazakov
2003-11-07 10:29 ` Dmitry A. Kazakov [this message]
2003-11-10 14:51 ` Lutz Donnerhacke
2003-11-10 17:52   ` Marius Amado Alves
2003-11-11  9:32     ` Lutz Donnerhacke
2003-11-11 12:24       ` Marius Amado Alves
2003-11-11 12:58         ` Lutz Donnerhacke
2003-11-11 16:09           ` Robert I. Eachus
2003-11-11 17:11             ` Marius Amado Alves
2003-11-12  9:21               ` Lutz Donnerhacke
  -- strict thread matches above, loose matches on Subject: below --
2003-11-06 17:26 amado.alves
2003-11-06 17:33 amado.alves
2003-11-06 19:01 amado.alves
2003-11-11 18:38 ` Georg Bauhaus
2003-11-11 21:27   ` Marius Amado Alves
2003-11-12  0:23     ` Georg Bauhaus
2003-11-12 11:29 amado.alves
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox