From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Simple example on interfaces
Date: Mon, 25 Jan 2021 17:41:59 +0100 [thread overview]
Message-ID: <rumsck$nfj$1@gioia.aioe.org> (raw)
In-Reply-To: f44498d1-8675-44b2-af1e-3937dcbc7a1fn@googlegroups.com
On 2021-01-25 17:08, Mario Blunk wrote:
> I'm trying to solve a problem of multiple inheritance. It seems to me that an interface could be the solution although the interface is still a mystery for me.
>
> This is the example code:
> https://github.com/Blunk-electronic/ada_training/blob/master/src/interfaces_1/interfaces_1.adb
>
> The problem to solve is:
> Type_A2 and type_B1 shall have the property p2 which is type_enum. The anchestors of type_A2 and type_B1 must not have this property.
> Both type_A2 and type_B1 shall inherit p2 from type_C so that p2 must not be written all over again. Would an interface be the solution ?
You must define "property." What is it? In your code these types have p2
already. Is this static polymorphism not enough? Do you need A2 and B1
in a class having p2, with polymorphic objects of the class? Then that
would indeed be an interface.
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.
But if p2 could be a function or a getter/setter pair then you can do this:
type P2_Interface is interface;
function P2 (Object : P2_Interface) return Enum is abstract;
type A2 is new A1 and P2_Interface with private;
overriding function P2 (Object : A2) return Enum;
type B1 is new Base and P2_Interface with private;
overriding function P2 (Object : B1) return Enum;
(I removed annoying "type_" prefix from all types)
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2021-01-25 16:41 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 [this message]
2021-01-25 17:51 ` Mario Blunk
2021-01-25 22:06 ` Dmitry A. Kazakov
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