comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Simple example on interfaces
Date: Mon, 25 Jan 2021 23:06:09 +0100	[thread overview]
Message-ID: <runfcf$1uub$1@gioia.aioe.org> (raw)
In-Reply-To: 9e1b5d67-be08-4f53-aadc-fbed761a8c24n@googlegroups.com

On 2021-01-25 18:51, Mario Blunk wrote:
> 
>> You must define "property." What is it?
> With "property" I mean the selectors like p0, p1 or p2.

They are components or else record members.

>> In your code these types have p2
>> already. Is this static polymorphism not enough?
> It seems so. Suppose there would be more types like C1, D1, ..., each of which derived from type_base, then
> I don't want to define p2 over and over.

There are two different things:

1. interface of a type (in general sense)
2. an implementation of

Ada interface is a type that has interface and no implementation. [It is 
a silly idea inherited from Java.]

So:

- if "define" applies to #1, then yes, you can inherit from Ada 
interface and thus you do not need to "define" inherited primitive 
operations like P2 again.

- if "define" applies to #2, then no, you cannot inherit implementation 
from Ada interface because it can have none.

The first non-abstract type inheriting from an Ada interface must 
implement its interface in full. The types derived from it will inherit 
that implementation. But each sibling as A2 and B1 must implement the 
interface anew.

>> Do you need A2 and B1
>> in a class having p2, with polymorphic objects of the class? Then that
>> would indeed be an interface.
> How would that look like ?

with declarations from the previous post:

    procedure Print_P2 (Object : P2_Interface'Class) is
    begin
       Put ("P2=" & Enum'Image (Object.P2));
    end Print_P2;

    X : A2;
    Y : B1;
begin
    Print_P2 (X);
    Print_P2 (Y);

>> Now, there is no full multiple inheritance in Ada, if p2 must be a
>> component, you are out of luck. You have only one shot and you have
>> spent it on p0 in the type Base.
> That is forbidden as far as the final application is concerned. The example I posted here is a simplification of a more complex scenario.

There exist various dirty tricks to emulate full multiple inheritance 
but no universal solution. If you really need full multiple inheritance, 
choose the most important path of implementations and make types along 
it proper types. Other paths if simple, could tricked using

- Min-in inheritance
- Generic packages to automate implementation of interfaces
- Memory pools to inject implementation

Nothing of these is good. They basically work only if the depths of the 
secondary inheritance paths is 1.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

  reply	other threads:[~2021-01-25 22:06 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-25 16:08 Simple example on interfaces Mario Blunk
2021-01-25 16:41 ` Dmitry A. Kazakov
2021-01-25 17:51   ` Mario Blunk
2021-01-25 22:06     ` Dmitry A. Kazakov [this message]
2021-01-26  7:33       ` G.B.
2021-01-26  8:07         ` Dmitry A. Kazakov
2021-01-26  8:17           ` Mario Blunk
2021-01-26  8:55             ` Dmitry A. Kazakov
2021-01-26  9:37       ` J-P. Rosen
2021-01-26 10:25         ` Dmitry A. Kazakov
2021-01-26 11:15           ` AdaMagica
2021-01-26 11:53             ` Dmitry A. Kazakov
2021-01-26 16:46               ` AdaMagica
2021-01-26 19:44                 ` Dmitry A. Kazakov
2021-01-26 20:04                   ` Shark8
2021-01-26 21:34                     ` Dmitry A. Kazakov
2021-01-27  3:11                     ` Randy Brukardt
2021-01-27 22:51                       ` Shark8
2021-01-30  8:33                         ` Randy Brukardt
2021-01-27  3:09                   ` Randy Brukardt
2021-01-27  8:05                     ` Dmitry A. Kazakov
2021-01-26 10:02     ` Stephen Leake
2021-01-25 17:00 ` Jeffrey R. Carter
2021-01-27  1:48   ` philip...@gmail.com
2021-01-27  8:06     ` Dmitry A. Kazakov
2021-01-27  3:36   ` Randy Brukardt
2021-01-27 23:04     ` Shark8
2021-01-25 19:05 ` Stephen Leake
replies disabled

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