* 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