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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Received: by 2002:ad4:498d:: with SMTP id t13mr23763778qvx.58.1579130396521; Wed, 15 Jan 2020 15:19:56 -0800 (PST) X-Received: by 2002:a9d:6544:: with SMTP id q4mr4625992otl.194.1579130396255; Wed, 15 Jan 2020 15:19:56 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.gegeweb.eu!gegeweb.org!usenet-fr.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!g89no898567qtd.0!news-out.google.com!w29ni1302qtc.0!nntp.google.com!g89no898558qtd.0!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 15 Jan 2020 15:19:55 -0800 (PST) In-Reply-To: <755521b8-d0a8-41bd-b547-da1136e3b8e1@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: google-groups.googlegroups.com; posting-host=70.109.61.2; posting-account=QF6XPQoAAABce2NyPxxDAaKdAkN6RgAf NNTP-Posting-Host: 70.109.61.2 References: <755521b8-d0a8-41bd-b547-da1136e3b8e1@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: How to stop inheritance in a good way? From: Jere Injection-Date: Wed, 15 Jan 2020 23:19:56 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader01.eternal-september.org comp.lang.ada:57849 Date: 2020-01-15T15:19:55-08:00 List-Id: On Wednesday, January 15, 2020 at 3:32:14 AM UTC-5, reinert wrote: > Assume I define a tagged record (or interface) + derived types: > > type int1_t is interface; > function A(x : int1_t) return Integer is abstract; > > type object1_t is abstract new int1_t with private; > function A(x : object1_t) return Integer; > function B(x : object1_t) return Integer; > > type object2_1_t is new object1_t with private; > function C(x : object2_1_t) return Integer; > > type object2_2_t is new object1_t with private; > function D(x : object2_2_t) return Integer; > > and I want object2_2_t *not* to inherit the function B (from type object1_t). > I can make a dummy function B for object2_2_t (to override), but is it a more elegant/proper way? Or I here somehow break the concept of inheritance and enter a "dead end" ? > > reinert It really depends on what you want object2_2_t to "be". If it truly has a public "is a" relationship to object1_t, then you have to accept B since that is part of the "contract" (bad wording I know) of object1_t. However if you are ok with object2_2_t being a descendant of int1_t (the origin of function A), then you can do something like the following (I added completions to your function so I could get it all to compile): package Test is type int1_t is interface; function A(x : int1_t) return Integer is abstract; type object1_t is abstract new int1_t with private; function A(x : object1_t) return Integer is (0); function B(x : object1_t) return Integer is (0); type object2_1_t is new object1_t with private; function C(x : object2_1_t) return Integer is (0); -- Note the change here type object2_2_t is new int1_t with private; function D(x : object2_2_t) return Integer is (0); private type object1_t is abstract new int1_t with null record; type object2_1_t is new object1_t with null record; -- See how the inheritance is listed differently type object2_2_t is new object1_t with null record; end Test;