comp.lang.ada
 help / color / mirror / Atom feed
From: Matthew Heaney <matthew_heaney@acm.org>
Subject: Re: Help - Constructors - ASAP.
Date: 1998/08/01
Date: 1998-08-01T00:00:00+00:00	[thread overview]
Message-ID: <m3vhodvevl.fsf@mheaney.ni.net> (raw)
In-Reply-To: dewar.901945397@merv

dewar@merv.cs.nyu.edu (Robert Dewar) writes:

> Well, the cases where safe inheritance would be feasible are limited to
> extensions of the type with no additional fields, not very useful!

This is the Ada 95 counterpart to the "Transitivity of Visibility"
technique described in the Ada 83 Rationale.

This is helpful when you have a type that comes into existence because
of a nested instantation.  For example:

generic
...
package GQ is 

   type T is tagged ...;
...
end GQ;

with GQ;
pragma Elaborate_All (GQ);

package P is
...
   package Q is new GQ (...);

   type T is new Q.T with null record;
...
end P;

What you do NOT want to happen is to for a client to have to refer to
P.Q.T.  The client shouldn't have to care that T was brought into
existence because of an instantiation; it's really an implementation
detail.  By using transitivity of visibility, the client can just refer
to P.T, in effect "hiding" the fact that T comes from Q.

You can do this with non-tagged types too.  One common mistake I see
programmers make is to do this:

package P is

   package Bounded_Strings_20 is
     new Ada.Strings.Bounded.Generic_Bounded_Length (20);
...
end P;

Now every client in the universe has to refer to the string type as
P.Bounded_Strings_20.Bounded_String.  Why should a client care?  

Use the transitivity of visibility technique to bring the string type
directly in the scope of P:

package P is

   package Bounded_Strings_20 is
     new Ada.Strings.Bounded.Generic_Bounded_Length (20);

   type Bounded_String is
     new Bounded_Strings_20.Bounded_String;
...
end P;

Now a client can just refer to P.Bounded_String.

Ah, simple.  Life is good.

Matt





  reply	other threads:[~1998-08-01  0:00 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-07-23  0:00 Help - Constructors - ASAP Maxim Senin
1998-07-26  0:00 ` Matthew Heaney
1998-07-27  0:00   ` dennison
1998-07-30  0:00     ` Robert I. Eachus
1998-07-30  0:00       ` tedennison
1998-07-31  0:00         ` Mats Weber
1998-07-31  0:00           ` Robert I. Eachus
1998-08-01  0:00             ` Matthew Heaney
1998-07-31  0:00           ` dennison
1998-08-01  0:00             ` Matthew Heaney
1998-08-01  0:00             ` Robert Dewar
1998-08-01  0:00               ` Matthew Heaney
1998-08-03  0:00             ` Mats Weber
1998-07-31  0:00         ` Matthew Heaney
1998-08-01  0:00       ` Robert Dewar
1998-08-01  0:00         ` Matthew Heaney [this message]
1998-08-03  0:00           ` Mats Weber
1998-08-03  0:00             ` Matthew Heaney
1998-08-03  0:00               ` Mats Weber
1998-08-04  0:00                 ` Matthew Heaney
1998-08-04  0:00                   ` Mats Weber
1998-08-05  0:00                     ` Matthew Heaney
1998-08-10  0:00           ` Robert I. Eachus
1998-08-03  0:00         ` tedennison
  -- strict thread matches above, loose matches on Subject: below --
1998-07-15  0:00 Maxim Senin
1998-07-16  0:00 ` 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