comp.lang.ada
 help / color / mirror / Atom feed
* Giving a package specification access to the private types of another package
@ 2002-12-10 13:51 Steven Murdoch
  2002-12-10 13:53 ` Preben Randhol
  0 siblings, 1 reply; 19+ messages in thread
From: Steven Murdoch @ 2002-12-10 13:51 UTC (permalink / raw)


I would like to use a package A from within another package B, however
the specification of A uses types that are declared in the private part
of package B. I could solve this by inserting the contents of the package
A in B, but is there another way with which I can keep the two files
separate (so as to improve clarity).

Steven Murdoch.



^ permalink raw reply	[flat|nested] 19+ messages in thread
* Re: Giving a package specification access to the private types of another package
@ 2002-12-10 14:27 Grein, Christoph
  2002-12-10 14:46 ` Steven Murdoch
  0 siblings, 1 reply; 19+ messages in thread
From: Grein, Christoph @ 2002-12-10 14:27 UTC (permalink / raw)


> It already is, but I have the same problem. I think if A is a child of
> B then the body of A can see the body of B, but the public specification of

No, that's wrong. No unit can ever see inside the body of another unit. The body 
is hidden from all visibility.

> A cannot see the body of B (which is what I need).

A child'body of a unit can see in the private part of its parent.
A private child's spec can see in the private part of its parent.
A child's private part can see in the private part of its parent.

Privateness can be nested. You can have private children of public parents, but 
also public children of private parents and private children of private parents. 


        package A     is ... end A;
private package A.B   is ... end A.B;
        package A.B.C is ... end A.B.C;  -- public within A.B
private package A.B.D is ... end A.B.D;  -- private within A.B

A.B.C'Spec does not see A.B.D (because the latter is private).
A.B.C'Body does see A.B.D'Spec.

with A;      -- legal
with A.B;    -- illegal
with A.B.C;  -- illegal
package X is ...



^ permalink raw reply	[flat|nested] 19+ messages in thread
* Re: Giving a package specification access to the private types of another package
@ 2002-12-11  5:51 Grein, Christoph
  2002-12-11 19:22 ` Jeffrey Carter
  0 siblings, 1 reply; 19+ messages in thread
From: Grein, Christoph @ 2002-12-11  5:51 UTC (permalink / raw)


This is indeed the perfect design for your problem.

> I think this is what I have done - and it works. My code is equivalent
> to the example below. This works and seems to be the best way to do it.
> 
> package B is
>    procedure Proc_B;
> private
>     type Private_Type is new Integer;
> end B;
> 
> with B.A;
> package body B is
>    procedure Proc_B is
>       Temp: Private_Type;
>    begin
>       A.Foobar(Temp);
>    end;
> end B;
> 
> private package B.A is
>    procedure Foobar(Temp: in Private_Type);
> end B.A;
> 
> package body B.A is
>    procedure Foobar(Temp: in Private_Type) is
>    begin
>       null;
>    end;
> end B.A;



^ permalink raw reply	[flat|nested] 19+ messages in thread
* Re: Giving a package specification access to the private types of another package
@ 2002-12-12  7:14 Grein, Christoph
  2002-12-12 17:01 ` Jeffrey Carter
  0 siblings, 1 reply; 19+ messages in thread
From: Grein, Christoph @ 2002-12-12  7:14 UTC (permalink / raw)


> Grein, Christoph wrote:
> > This is indeed the perfect design for your problem.
> > 
> >>I think this is what I have done - and it works. My code is equivalent
> >>to the example below. This works and seems to be the best way to do it.
> >>
> >>package B is
> >>   procedure Proc_B;
> >>private
> >>    type Private_Type is new Integer;
> >>end B;
> >>
> >>with B.A;
> >>package body B is
> >>   procedure Proc_B is
> >>      Temp: Private_Type;
> >>   begin
> >>      A.Foobar(Temp);
> >>   end;
> >>end B;
> >>
> >>private package B.A is
> >>   procedure Foobar(Temp: in Private_Type);
> >>end B.A;
> >>
> >>package body B.A is
> >>   procedure Foobar(Temp: in Private_Type) is
> >>   begin
> >>      null;
> >>   end;
> >>end B.A;
> 
> Perfect? That's a bit strong. It's a good design, but as given, I think 
> that putting Foobar in B (perhaps with "is separate") is as good.

I beg to differ. For this tiny example, you're right. But IIRC, the OP said that 
his package B.A was quite big and held a big part of the implementation stuff of 
B. Then child packages are the "perfect" design because you can split one big 
body (B) is several smaller children dedicated to specific subproblems.



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

end of thread, other threads:[~2002-12-13 20:25 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-10 13:51 Giving a package specification access to the private types of another package Steven Murdoch
2002-12-10 13:53 ` Preben Randhol
2002-12-10 14:07   ` Steven Murdoch
2002-12-10 14:37     ` James S. Rogers
2002-12-10 14:54       ` Steven Murdoch
2002-12-10 15:54         ` Robert A Duff
2002-12-10 16:58           ` Steven Murdoch
2002-12-11  2:43             ` SteveD
2002-12-10 19:42     ` Stephen Leake
2002-12-10 14:36   ` Steven Murdoch
  -- strict thread matches above, loose matches on Subject: below --
2002-12-10 14:27 Grein, Christoph
2002-12-10 14:46 ` Steven Murdoch
2002-12-10 15:08   ` John Cupak
2002-12-10 15:31     ` Steven Murdoch
2002-12-11  5:51 Grein, Christoph
2002-12-11 19:22 ` Jeffrey Carter
2002-12-12  7:14 Grein, Christoph
2002-12-12 17:01 ` Jeffrey Carter
2002-12-13 20:25   ` Steven Murdoch

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