From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,93d7def3eeefbc26 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!z14g2000cwz.googlegroups.com!not-for-mail From: danmcleran@hotmail.com Newsgroups: comp.lang.ada Subject: Re: Private area and child packages Date: 31 Dec 2004 09:55:09 -0800 Organization: http://groups.google.com Message-ID: <1104515709.303592.320410@z14g2000cwz.googlegroups.com> References: <1104293158.276241.42640@f14g2000cwb.googlegroups.com> NNTP-Posting-Host: 172.163.236.126 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1104515747 6125 127.0.0.1 (31 Dec 2004 17:55:47 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 31 Dec 2004 17:55:47 +0000 (UTC) User-Agent: G2/0.2 Complaints-To: groups-abuse@google.com Injection-Info: z14g2000cwz.googlegroups.com; posting-host=172.163.236.126; posting-account=LSix6gsAAACmBFWMCbh6syCaua0lawvj Xref: g2news1.google.com comp.lang.ada:7347 Date: 2004-12-31T09:55:09-08:00 List-Id: 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.