comp.lang.ada
 help / color / mirror / Atom feed
From: eachus@spectre.mitre.org (Robert I. Eachus)
Subject: Re: Another OOP Question
Date: 1996/08/20
Date: 1996-08-20T00:00:00+00:00	[thread overview]
Message-ID: <EACHUS.96Aug20165304@spectre.mitre.org> (raw)
In-Reply-To: JSA.96Aug20123514@alexandria



     I assume that the problem is that you want only part of the
private properties of the parent to be visible to the child.
There is a trick you can use in Ada 95 which may help with what
you want.  Actually, make that two tricks...

     package Foo is

       type Parent is tagged private;
       --visible methods on parent

     private

       package Hidden is
         type Real_Parent is tagged private;
         -- some partially hidden methods here.
       private
         type Real_Parent is tagged record....
         --really well hidden methods here.
       end Hidden;
        
       type Parent is new Real_Parent with...
       -- hidden methods here too.

     end Foo;      
 
     Now in children the public methods will be visible.  In the
private part, the hidden methods will be visible, but the state
variables declared in the private part of Hidden.Real_Parent will not
be visible.  Also the operations in the private part of Hidden will be
derived, but will not be visible in any children or directly in the
body of Foo.  Unless they override visible methods--for instance if
Real_Parent is a derived type--the only way to access the really well
hiden methods is through the visible operations in Hidden.
         
    Oh, I promised you a second way:

     package Foo is

       type Parent is tagged private;
       --visible methods on parent

     private

       type Parent is new with...

       package Hidden is
         -- some partially hidden methods here.
       private
         --really well hidden methods here.
       end Hidden;
        
       -- and some hidden methods here.

     end Foo;      
 
     In this method the operations in Hidden are not derived for type
Parent which may be and advantage.  The visible operations in Hidden
can be used on child types, but you need to do explicit conversions.
This technique is very useful if you are defining operations which
shouldn't be implicitly derived for child types.


--

					Robert I. Eachus

with Standard_Disclaimer;
use  Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...




  reply	other threads:[~1996-08-20  0:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-08-20  0:00 Another OOP Question Spasmo
1996-08-20  0:00 ` Jon S Anthony
1996-08-20  0:00   ` Robert I. Eachus [this message]
  -- strict thread matches above, loose matches on Subject: below --
1996-08-21  0:00 Spasmo
1996-08-22  0:00 ` Jon S Anthony
1996-08-21  0:00 Spasmo
1996-08-18  0:00 Spasmo
1996-08-19  0:00 ` Jon S Anthony
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox