comp.lang.ada
 help / color / mirror / Atom feed
From: jsa@alexandria (Jon S Anthony)
Subject: Re: Another OOP Question
Date: 1996/08/19
Date: 1996-08-19T00:00:00+00:00	[thread overview]
Message-ID: <JSA.96Aug19143910@alexandria> (raw)
In-Reply-To: 4v609i$fgj@Masala.CC.UH.EDU


In article <4v609i$fgj@Masala.CC.UH.EDU> cosc19z5@Bayou.UH.EDU (Spasmo) writes:

> Ok, here's another OOP question about accessing private members.
> Right now let's say I have a class called A, and B inherits from
> A.  Now let's say that B needs to access a private data member
> in A -- is there any way I can do this without placing B into
> a Child package?  

I'm not sure I follow this.  Do you mean "private" in the C++ sense or in
the Ada sense?  In the Ada sense, if A and B are in the same package, then
you get this for free:

package P is

    type A is tagged private;
    ... ops for A...
    type B is new A with private;
    ... ops for B...

private
    type A is ...
    type B is ...
end P;

In the body of P, B's ops can access A's private definition no problem.


If you want A and B in separate packages, then in order for the impls of
B's ops to have access to the private definition of A, it needs to go into
a child package.

> The reason I'd like to now is because I'm confronted with such a
> scenario and Child packages (among other things) will make all of my
> parents members visible which is the last thing I want to do.

I don't understand why you make this claim.  Children do not make any of
the private stuff of the parent visible:

package P is
    type A is tagged private;
    ...
private
    type A is...
end P;


package P.C is
--
-- None of P's private definitions are visible here.
    type B is new A with private;
    ...
private
--
-- P's private section is visible here and in the body of P.C
    type B is ...
end P.C;


with P.C;
procedure Proc is
--
-- Nothing of P's private section is visible here...
...
end Proc;


My guess is that you are not clear on child package visibility rules
and that you really do want to use a child package and that it will
work just fine for what you want to achieve.

Lastly, if you mean "private" in the C++ sense, you have to put the actual
definitions in the _bodies_ of the packages.  The only way for anything
else to get at these will be through accessors (public or private) defined
in the specification.  Nothing outside the body (and any separates) has
direct access.

/Jon
-- 
Jon Anthony
Organon Motives, Inc.
1 Williston Road, Suite 4
Belmont, MA 02178

617.484.3383
jsa@organon.com





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

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