comp.lang.ada
 help / color / mirror / Atom feed
From: danmcleran@hotmail.com
Subject: Re: Private area and child packages
Date: 31 Dec 2004 09:55:09 -0800
Date: 2004-12-31T09:55:09-08:00	[thread overview]
Message-ID: <1104515709.303592.320410@z14g2000cwz.googlegroups.com> (raw)
In-Reply-To: aHqAd.11670$RH4.11125@newsread1.news.pas.earthlink.net

Jeffrey Carter wrote:
> danmcleran@hotmail.com wrote:
>
> > Is there any way to hide implementation detail from child packages?
An
> > example, say I have a parent package like this:
> >
> > package Some_Package is
> > type Secret_Type is private;
> > private
> > type Secret_Type is record
> > Secret_Value : Integer := 0;
> > end record;
> > end Some_Package;
> >
> > I don't want any other component to be able to manipulate the
> > Secret_Value record component, not even a child package of
> > Some_Package.
>
> If you don't need to make the type visible at all, you can simply
> declare it in the package body. Items in package bodies are hidden
from
> all other scopes.
>
> If you want the type to be visible, but its implementation to be
hidden,
> you can use a pointer:
>
> package P is
>     type Something is [limited] private;
>
>     -- operations on Something
> private -- P
>     type Implementation;
>     type Something is access [all] Implementation;
> end P;
>
> The full view of Implementation must then be given in the body of P.
If
> you do this, you're responsible for the memory management of
Something.
> This is usually easier if you make Something limited, since the
client
> cannot then make copies of the access values, eliminating
opportunities
> for dangling references.
>
> --
> Jeff Carter
> "Beyond 100,000 lines of code you
> should probably be coding in Ada."
> P. J. Plauger
> 26


But then how do I know when the access to the Implementation object
goes out of scope? It seems to me that I need to either derive from
Ada.Finalization.Limited_Controlled or define Something as a smart
pointer to Implementation.




  parent reply	other threads:[~2004-12-31 17:55 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-29  4:05 Private area and child packages danmcleran
2004-12-29  4:47 ` tmoran
2004-12-29 15:10   ` danmcleran
2004-12-30 18:51     ` tmoran
2005-01-01  3:45       ` danmcleran
2004-12-29  4:49 ` Jeffrey Carter
2004-12-29 15:27   ` danmcleran
2004-12-29 16:53     ` Samuel Tardieu
2004-12-30  4:07       ` Jeffrey Carter
2004-12-30 15:31   ` danmcleran
2004-12-30 18:14     ` Jeffrey Carter
2004-12-31 17:55   ` danmcleran [this message]
     [not found]   ` <1104515735.052116.248180@c13g2000cwb.googlegroups.com>
2004-12-31 19:02     ` Jeffrey Carter
2004-12-29 19:05 ` Martin Krischik
2004-12-29 21:44 ` Stephen Leake
replies disabled

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