comp.lang.ada
 help / color / mirror / Atom feed
From: "Norman H. Cohen" <ncohen@watson.ibm.com>
Subject: Re: preventing inheritance
Date: 1996/12/16
Date: 1996-12-16T00:00:00+00:00	[thread overview]
Message-ID: <32B5A234.947@watson.ibm.com> (raw)
In-Reply-To: 32B22CDC.3FE4@bix.com


Tom Moran wrote:
 
> Given
> type T is tagged ...
> procedure A(X:T)
> function  B(X:T) return ...
> procedure C(X:T)
>   and
> Type U is new T with ...
> procedure D(X:T)
> procedure E(X:T)
> function  F(X:T) return ...
> 
>   BUT
> B(X:U) is, for reasons beyond my control, illegal.
> 
>   What is the best way to prevent/catch B(X:U)?
> 
> Currently I replace the inherited B(X:U) with
> function  B(X:U) return ... is
> begin
>   raise this_is_a_no_no;
>   return 0; -- all functions need at least one return
> end B;

Apparently, when you say that B(X:U) is "illegal", what you mean is that
B is an operation that, for reasons having to do with your application,
does not have a sensible interpretation for objects of type U.

In this case, your inheritance hierarchy is inappropriate, since it
violates the "is-a" rule.  Since U is derived from T, it should be the
case that a U "is a" special kind of T, and therefore that anything that
can be done with a T (e.g. applying operation B to it) should also be
doable to a U.

Quite properly, Ada does not provide a way to prevent inheritance of an
operation from a parent tagged type.

What you should do is reorganize your hierarchy.  For example, you might
create a new abstract root type, say S, whose operations are the
operations common to both your original T and your original U, then
derive both T and U from S:

 type S is abstract tagged ...
 procedure A(X:S)
 procedure C(X:S)

 type T is new S with ...
  -- inherits A(X:T) and C(X:T)
 function  B(X:T) return ...

 type U is new S with ...
 -- inherits A(X:U) and C(X:U)
 procedure D(X:U)
 procedure E(X:U)
 function  F(X:U) return ...

-- 
Norman H. Cohen
mailto:ncohen@watson.ibm.com
http://www.research.ibm.com/people/n/ncohen




  reply	other threads:[~1996-12-16  0:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-12-13  0:00 preventing inheritance Tom Moran
1996-12-16  0:00 ` Norman H. Cohen [this message]
1996-12-16  0:00   ` Tom Moran
1996-12-16  0:00     ` Tom Moran
1996-12-17  0:00       ` Larry Kilgallen
1996-12-18  0:00       ` Norman H. Cohen
1996-12-18  0:00         ` Tom Moran
1996-12-19  0:00     ` Robert I. Eachus
replies disabled

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