comp.lang.ada
 help / color / mirror / Atom feed
* How to hide methods in child classes?
@ 1996-03-20  0:00 Paul Whittington
  1996-03-20  0:00 ` Norman H. Cohen
  1996-03-21  0:00 ` John G. Volan
  0 siblings, 2 replies; 3+ messages in thread
From: Paul Whittington @ 1996-03-20  0:00 UTC (permalink / raw)


How, in a child class, do I hide (make them private) class methods
inherited from the parent class?







^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How to hide methods in child classes?
  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
  1 sibling, 0 replies; 3+ messages in thread
From: Norman H. Cohen @ 1996-03-20  0:00 UTC (permalink / raw)


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?

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.

--
Norman H. Cohen    ncohen@watson.ibm.com




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How to hide methods in child classes?
  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
  1 sibling, 0 replies; 3+ messages in thread
From: John G. Volan @ 1996-03-21  0:00 UTC (permalink / raw)



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?" );
------------------------------------------------------------------------




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1996-03-21  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox