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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d10596e187e90822 X-Google-Attributes: gid103376,public From: Richard D Riehle Subject: Re: Private Children Date: 1999/06/23 Message-ID: <7kr4pc$bb9@dfw-ixnews15.ix.netcom.com>#1/1 X-Deja-AN: 493013375 References: <7klja3$c0p$1@nnrp1.deja.com> <376E70A5.F77E558D@averstar.com> <376E9EEB.322A3F39@averstar.com> <7kmoe4$o83@dfw-ixnews15.ix.netcom.com> Organization: Netcom X-NETCOM-Date: Wed Jun 23 12:16:28 PM CDT 1999 Newsgroups: comp.lang.ada Date: 1999-06-23T12:16:28-05:00 List-Id: In article , dale@cs.rmit.edu.au (Dale Stanbrough) wrote: >Yes I know that, but I'm not concerned about parent/child packages, but >about sibling (or rather non lineal descendant) packages/privacy issues. > >I think that the current situation forces too much exposure of >implementation issues that will cause package hierachies to end up >a large entagled mess, because we are continually forced to abandon >internal privacy goals to meet external ones. The Ada private part is analogous to the C++ protected part. A derivation of a C++ class may see the protected part of its parent. Ada has ways to strengthen the encapsulation if you wish. Private packages are one way. Another useful technique is opaque types. An opaque type is a type that contains nothing but a reference to data. This is quite easy using Ada's incomplete type definition. These can be tagged for extensibility while hiding all the details within a package body. Consider, package P is type T is tagged private; -- operations on T private type Item; type Item_Pointer is access all Item; type T is tagged record Data : Item_Pointer; -- a reference to hidden data end record; end P; Now T can still be extended, but the implementation of Item is deferred to the package body. If you want to be really clever, you can create a private child package of P where Item is fully defined in the private specification and with'ed into the body of P. This enforces the rule that nothing but a package body rooted at P can access the public specification of the private child. This preserves extensibility within the hierarchy but prevents access by any ordinary client. This example follows the Modula-2 convention for information hiding using opaque types. Note that Modula-3 improves upon this through reference types that are followed with a reserved word, REVEAL,in the IMPLEMENTATION MODULE. In the final analysis, though, encapsulation is something like the lock on a safe that is intended to keep honest people honest. If someone is determined to break encapsulation, they will find a way to do it, even if they have to crack open your package body and perform "open heart surgery." Richard Riehle richard@adaworks.com http://www.adaworks.com