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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,555956c1cdd22308 X-Google-Attributes: gid103376,public From: Matthew Heaney Subject: Re: Help - Constructors - ASAP. Date: 1998/08/01 Message-ID: #1/1 X-Deja-AN: 376895824 Sender: matt@mheaney.ni.net References: <6p75qi$rcj@news.latnet.lv> <6pi4jq$j73$1@nnrp1.dejanews.com> NNTP-Posting-Date: Fri, 31 Jul 1998 22:18:57 PDT Newsgroups: comp.lang.ada Date: 1998-08-01T00:00:00+00:00 List-Id: 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