From: John G. Volan <John_Volan@ccmail.dayton.saic.com>
Subject: Re: How to hide methods in child classes?
Date: 1996/03/21
Date: 1996-03-21T00:00:00+00:00 [thread overview]
Message-ID: <4irvc9$mcs@dayuc.dayton.saic.com> (raw)
In-Reply-To: 4inqqc$l63@mica.inel.gov
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?" );
------------------------------------------------------------------------
prev parent reply other threads:[~1996-03-21 0:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-03-20 0:00 How to hide methods in child classes? Paul Whittington
1996-03-20 0:00 ` Norman H. Cohen
1996-03-21 0:00 ` John G. Volan [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox