comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
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
Date: 2018-05-29T17:12:10-05:00	[thread overview]
Message-ID: <pekj85$tn0$1@franka.jacob-sparre.dk> (raw)
In-Reply-To: ecd599f8-bb04-4304-9242-1c88edee4a4e@googlegroups.com

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 
<new_anonymous_subtype>);" 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. 



  parent reply	other threads:[~2018-05-29 22:12 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-26 16:14 about inheritance of subtypes and entities (such as constants) related to a type in the same package Mehdi Saada
2018-05-26 16:44 ` Mehdi Saada
2018-05-29 22:07   ` Randy Brukardt
2018-05-29 22:12 ` Randy Brukardt [this message]
2018-05-30  8:13   ` Dmitry A. Kazakov
2018-05-30 19:25     ` Randy Brukardt
2018-05-30 19:45       ` Dmitry A. Kazakov
2018-05-30 19:59         ` Randy Brukardt
2018-05-31  8:44           ` Dmitry A. Kazakov
2018-05-31 22:48             ` Randy Brukardt
2018-05-31 23:39               ` Mehdi Saada
2018-06-01  2:50                 ` Shark8
2018-06-01  7:35                 ` Dmitry A. Kazakov
2018-05-30 20:53   ` Dan'l Miller
2018-05-31  8:54     ` Dmitry A. Kazakov
2018-05-31 14:29       ` Dan'l Miller
2018-05-31 14:38         ` Dan'l Miller
2018-05-31 17:37         ` Dmitry A. Kazakov
2018-05-31 18:53           ` Dan'l Miller
2018-05-31 19:59             ` Dmitry A. Kazakov
2018-05-31 21:10               ` Dan'l Miller
2018-06-01  7:56                 ` Dmitry A. Kazakov
2018-06-01 14:01                   ` Dan'l Miller
2018-06-01 15:27                     ` Dmitry A. Kazakov
2018-05-31 22:45             ` Randy Brukardt
2018-05-31 23:50               ` Dan'l Miller
2018-06-01  7:38               ` Dmitry A. Kazakov
2018-05-31 22:34     ` Randy Brukardt
replies disabled

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