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.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC,YOU_INHERIT autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,899484222880ae7c X-Google-Attributes: gid103376,public From: "Norman H. Cohen" Subject: Re: preventing inheritance Date: 1996/12/16 Message-ID: <32B5A234.947@watson.ibm.com>#1/1 X-Deja-AN: 204434839 references: <32B22CDC.3FE4@bix.com> content-type: text/plain; charset=us-ascii organization: IBM Thomas J. Watson Research Center mime-version: 1.0 reply-to: ncohen@watson.ibm.com newsgroups: comp.lang.ada x-mailer: Mozilla 3.0 (Win95; I) Date: 1996-12-16T00:00:00+00:00 List-Id: 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