comp.lang.ada
 help / color / mirror / Atom feed
* Ada95 and multiple inheritance (how?)
@ 1997-01-29  0:00 Bruno Hemeury
  1997-01-29  0:00 ` Matthew Heaney
  0 siblings, 1 reply; 2+ messages in thread
From: Bruno Hemeury @ 1997-01-29  0:00 UTC (permalink / raw)



Hi, 


Is it right to say Ada95  does not support multiple inheritance or there are
ways to provide it with the facilities of the language?

It would be very helpful if you could provide references.

regards

Bruno





^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Ada95 and multiple inheritance (how?)
  1997-01-29  0:00 Ada95 and multiple inheritance (how?) Bruno Hemeury
@ 1997-01-29  0:00 ` Matthew Heaney
  0 siblings, 0 replies; 2+ messages in thread
From: Matthew Heaney @ 1997-01-29  0:00 UTC (permalink / raw)



In article <5cnvko$51q@miranda.gmrc.gecm.com>, Bruno Hemeury <byh> wrote:

>Is it right to say Ada95  does not support multiple inheritance or there are
>ways to provide it with the facilities of the language?

Yes, it is correct that Ada 95 does not support multiple inheritence. 
However, when you look at the things programmers use multiple inheritence
for in other languages, some common idioms emerge.  The language designers
of Ada 95 decided that you could program those idioms in the language using
existing facilities, without multiple inheritence.

Consider mixins.  In many languages, you have a bit a functionality that
you want to insert at the bottom of a hierarchy, and you use multiple
inheritence to do it.  In Ada 95, I can do mixin programming using generics
and (single) inheritence.

As an example, suppose I have already have a sequential data structure, and
I want to mix in guard functionality.  I do it like this:

[Warning: I just got my Ada 95 compiler yesterday (thank you Tenon!) so my
syntax may be a little off.]

Here's my sequential data structure:

generic
   type Stack_Item is private;
pacakge Stacks is

   type Stack is private;

   procedure Push (Item : in Stack_Item; On : in out Stack);
...
end Stacks;

Now here's my guard mixin:

generic
   type T is tagged limited private;  -- syntax may be wrong
package Guard_Mixin is
  
   type Guarded_T is new T with private;

   procedure Seize (O : in out Guarded_T);
      -- Sorry, Edsgar, about not using the Dutch name, but Robert
      -- Dewar will yell at me if we don't speak English on cla

   procedure Release (O : in out Guarded_T);

...

end Guard_Mixin;

To add the guard functionality to the stack, just instantiate as follows:

package Integer_Stacks is
   new Stacks (Integer);

package Integer_Stacks.Guarded is
   new Guard_Mixin (Integer_Stacks.Stack);

subtype Integer_Stack is Integer_Stacks.Guarded.Guarded_T;

And then in some scope:

declare
   The_Stack : Integer_Stack;
begin
   Seize (The_Stack);

Cool, huh?

The Ada 95 Rationale is must reading, and is one reference where you'll
find examples of how to do practice the idioms (that require multiple
inheritence in other languages, but not Ada 95).

The Ada 95 Rational is on the web; navigate there by visiting the Home of
the Brave Ada Programmers.

<http://www.adahome.com>

matt

--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
<mailto:matthew_heaney@acm.org>
(818) 985-1271




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1997-01-29  0:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-01-29  0:00 Ada95 and multiple inheritance (how?) Bruno Hemeury
1997-01-29  0:00 ` Matthew Heaney

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