From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Path: eternal-september.org!reader02.eternal-september.org!paganini.bofh.team!weretis.net!feeder8.news.weretis.net!news.mixmin.net!aioe.org!5WHqCw2XxjHb2npjM9GYbw.user.gioia.aioe.org.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Simple example on interfaces Date: Mon, 25 Jan 2021 17:41:59 +0100 Organization: Aioe.org NNTP Server Message-ID: References: NNTP-Posting-Host: 5WHqCw2XxjHb2npjM9GYbw.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 Content-Language: en-US X-Notice: Filtered by postfilter v. 0.9.2 Xref: reader02.eternal-september.org comp.lang.ada:61194 List-Id: 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