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,5f29e39fb3307df1 X-Google-Attributes: gid103376,public From: John G. Volan Subject: Re: How to hide methods in child classes? Date: 1996/03/21 Message-ID: <4irvc9$mcs@dayuc.dayton.saic.com>#1/1 X-Deja-AN: 143485718 distribution: world references: <4inqqc$l63@mica.inel.gov> content-type: text/plain; charset=ISO-8859-1 x-xxmessage-id: organization: Science Applications International Corp. (SAIC) mime-version: 1.0 newsgroups: comp.lang.ada Date: 1996-03-21T00:00:00+00:00 List-Id: In article <4inqqc$l63@mica.inel.gov>, paul@srv.net (Paul Whittington) writes: |> How, in a child class, do I hide (make them private) class methods |> inherited from the parent class? Norman Cohen responded: >This is generally considered to be methodologically unsound. It should >be possible for an object of the subclass to be usable in all the same >ways as an object of the superclass (and typically in additional ways as >well). In particular, it should be possible to invoke those methods you >want to hide. What Norman says is quite true. However, there is an alternative arrangement that might be methodologically sound: private inheritance. This entirely hides fact that the subclass is inheriting from the superclass at all. _All_ of the inherited methods are hidden. This technique is sometimes called "implementation inheritance" because the subclass simply reuses the implementation of the superclass, but does not publicly represent itself as supporting Liskov type substitutability with respect to the the superclass. Here's how to do it in C++: class A { ... }; class B : private A { // B secretly inherits from A public: ... // none of A's data members visible to clients of B ... // none of A's member functions visible to clients of B private: ... }; And here's how to do in Ada95: package A is type T is tagged ... ; end A; package B is type T is tagged ... private; -- none of A's record components -- visible to clients of B ... -- none of A.T's primitive subprograms visible to clients of B private type T is new A.T with ... -- B.T is secretly derived from A.T end B; ------------------------------------------------------------------------ Internet.Usenet.Put_Signature ( Name => "John G. Volan", E_Mail => "John_Volan@dayton.saic.com", Favorite_Slogan => "Ada95: The *FIRST* International-Standard OOPL", Humorous_Disclaimer => "These opinions are undefined by SAIC, so" & "any use would be erroneous ... or is that a bounded error now?" ); ------------------------------------------------------------------------