comp.lang.ada
 help / color / mirror / Atom feed
From: stt@spock.camb.inmet.com (Tucker Taft)
Subject: Re: Type extension questions
Date: Thu, 23 Mar 1995 22:03:59 GMT
Date: 1995-03-23T22:03:59+00:00	[thread overview]
Message-ID: <D5wyMo.M1M@inmet.camb.inmet.com> (raw)
In-Reply-To: D5tFuE.1vx@ennews.eas.asu.edu

Harry Koehnemann (koehnema@enuxsa.eas.asu.edu) wrote:

: I have a couple questions on Ada95 tagged types.  These appear to be
: easy questions, but I can't seem to locate an answer for either.
: LRM references would also be appreciated with an answer.

: 1) Is it possible to derive a type such that the parent operations are not
:    available to the user of the new type?  This question is equivalent to
:    the ability to do private inheritance ala C++ - class B: private A { ...};
:    I would assume the answer is yes, but haven't yet figured out how.

Just declare the new type as a tagged private type (RM95 7.3(2)):

   type T is tagged private;
   ...
 private
   type T is new P with record ...

Or, if you want to make it visible that you are derived from some
ancestor of P, but not that you are derived from P directly
(see RM95 7.3(3)):

   type T is new P_Ancestor with private;
   ...
 private
   type T is new P with record ...  
         -- presuming P is descended from P_Ancestor

Even simpler is to use the "privately" inherited type as a component.
In many cases, type extension is overkill for purely private "implementation" 
inheritance.  Simply making P a component eliminates any complexity
relating to multiple inheritance, etc.

: 2) Can a derived type declare a component with the same name as a parent
:    component?  At the risk of being lectured on GNAT's incompleteness :),
:    GNAT allows a new same-name components if the parent type is private and
:    the child type is public, but does gives an error if the child and parent
:    are both public or private.  I assume the answer is one or the other,
:    not "if one is private and one is public...".  Other OO languages allow
:    this in their inheritance and I assume Ada95 does as well.

Only inherited subprograms can be overridden; inherited 
components cannot (RM95 8.3(9-13)).

You may not repeat names if both components would ever be visible
at the same place (RM95 8.3(26)).  

This rule is repeated as a Note in RM95 3.9.1(9) -- Note #69 of Section 3.

What this means is that you can reuse a name of a non-discriminant
component only if the parent type is private.  You can reuse
the name of a (visible) discriminant of the parent only if a new 
discriminant_part is given in the declaration of the type extension.

Even if the parent type is private, you can't reuse the name
if the record extension is declared in a child of the package
containing the private type declaration, because once you 
get to the private part or body of the child, both would
be visible (RM95 7.3.1(4)).  (I fear that as I now reread 7.3.1(4) 
and 8.3(26), the intent of these rules for handling this special case 
might have gotten a bit garbled in the RM-ease...)

: Thanks.

: --
: Harry Koehnemann			Arizona State University
: hek@asu.edu				Computer Science Department

-Tucker Taft   stt@inmet.com
Intermetrics, Inc.



      parent reply	other threads:[~1995-03-23 22:03 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1995-03-22  0:25 Type extension questions Harry Koehnemann
1995-03-22 12:01 ` Robb Nebbe
1995-03-23 22:05   ` Harry Koehnemann
1995-03-25  6:59     ` Cyrille Comar
1995-03-25  7:13     ` Cyrille Comar
1995-03-27  0:00       ` Norman H. Cohen
1995-03-30  0:00         ` Cyrille Comar
1995-03-27 17:29       ` Harry Koehnemann
1995-03-27 20:26         ` Robert I. Eachus
1995-03-29  0:00           ` Harry Koehnemann
1995-03-27 20:37         ` Kennel
1995-03-23 22:03 ` Tucker Taft [this message]
replies disabled

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