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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,97062b5fe1a67fd3 X-Google-Attributes: gid103376,public From: mheaney@ni.net (Matthew Heaney) Subject: Re: Ada95 and multiple inheritance (how?) Date: 1997/01/29 Message-ID: #1/1 X-Deja-AN: 213183534 references: <5cnvko$51q@miranda.gmrc.gecm.com> content-type: text/plain; charset=ISO-8859-1 organization: Estormza Software mime-version: 1.0 newsgroups: comp.lang.ada Date: 1997-01-29T00:00:00+00:00 List-Id: In article <5cnvko$51q@miranda.gmrc.gecm.com>, Bruno Hemeury 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. matt -------------------------------------------------------------------- Matthew Heaney Software Development Consultant (818) 985-1271