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.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!nntp-feed.chiark.greenend.org.uk!ewrotcd!newsfeed.xs3.de!io.xs3.de!news.jacob-sparre.dk!franka.jacob-sparre.dk!pnx.dk!.POSTED.rrsoftware.com!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: about inheritance of subtypes and entities (such as constants) related to a type in the same package Date: Tue, 29 May 2018 17:12:10 -0500 Organization: JSA Research & Innovation Message-ID: References: Injection-Date: Tue, 29 May 2018 22:12:21 -0000 (UTC) Injection-Info: franka.jacob-sparre.dk; posting-host="rrsoftware.com:24.196.82.226"; logging-data="30432"; mail-complaints-to="news@jacob-sparre.dk" X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246 Xref: reader02.eternal-september.org comp.lang.ada:52768 Date: 2018-05-29T17:12:10-05:00 List-Id: Inheritance in Ada was designed by Ichbiah in the late 1970s, long before anyone really understood OOP or similar systems. It's (IMHO) not very well designed, but we're stuck with it. The *only* things inherited in Ada is primitive subprograms and operators. Some predefined stuff like memberships gets regenerated for each type. Otherwise, there's no inheritance. Objects and subtypes in particular are not part of it. (Depending on the use, you may or may not want them, but it isn't possible at all.) In the case of constants, there's an easy solution: use a function instead. Otherwise, though, you have to be careful. Changing inheritance would be wildly incompatible, so I don't think there is any chance of that. Randy. "Mehdi Saada" <00120260a@gmail.com> wrote in message news:ecd599f8-bb04-4304-9242-1c88edee4a4e@googlegroups.com... Hello. In my reading of Barnes' book I learn many little details that aren't apparent in the rm... no surprise. Being used to much readability, I'm surprised, however, by the situation with inheritance: with Ada.Text_IO; package AA is type A is private; subtype B is A; function IS_IN_B(obj: A) return boolean; procedure TEst_B (Obj_B: B) is Null; private type A is new Integer; end AA; So if I derive a new type from A in another package, it would inherit IS_IN, but not the declaration of B ? This declaration would become anonymous and I would have to means to get, say, B'range or whatever attributes it has ("private" was for convenience), but to look in package AA from where A comes ? Also, no being able to do things like "pragma Assert (Obj in );" seems pretty lame. Or did I misunderstood something ? It could have been decided that subtypes of a type declared in the same package, are inherited as would be subprograms. Same goes for constants. Which subtype B is mentioned (from A or C) would be resolved at least at compile time. Having the same name isn't that good, but that's secondary.