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,b8b8a54001adc4d2 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: Possible Ada deficiency? Date: 31 Dec 2004 17:52:49 -0800 Organization: http://groups.google.com Message-ID: <1104544369.712132.159910@z14g2000cwz.googlegroups.com> References: <1104516913.718856.94090@z14g2000cwz.googlegroups.com> NNTP-Posting-Host: 172.167.82.162 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1104544373 18999 127.0.0.1 (1 Jan 2005 01:52:53 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 1 Jan 2005 01:52:53 +0000 (UTC) In-Reply-To: User-Agent: G2/0.2 Complaints-To: groups-abuse@google.com Injection-Info: z14g2000cwz.googlegroups.com; posting-host=172.167.82.162; posting-account=LSix6gsAAACmBFWMCbh6syCaua0lawvj Xref: g2news1.google.com comp.lang.ada:7362 Date: 2004-12-31T17:52:49-08:00 List-Id: Jeffrey Carter wrote: > danmcleran@hotmail.com wrote: > > > In C++ and Java, no private data can be seen by child classes. I think > > that Ada would benefit from extending its information hiding > > capabilities by allowing a package writer to conceal type information > > from child packages. > > You're confusing C++ classes with Ada packages. In C++, classes serve a > multitude of purposes, including encapsulation, information hiding, type > extension, and dynamic dispatching. In Ada, encapsulation, name space > control, and information hiding are handled by packages. Type extension > and dispatching are handled by tagged types. > > Private components in C++ prevent the components from being visible to > derived types. This is also possible in Ada: > > package P is > type T is tagged private; > > procedure Op (A : in out T); > private -- P > type T is tagged record > I : Integer := 0; > end record; > end P; > > with P; > package Q is > type T is new P.T with record > F : Float := 0.0; > end record; > > procedure Op_2 (A : in out T); > end Q; > > package body Q is > procedure Op_2 (A : in out T) is > -- null; > begin -- Op_2 > A.I := 2; -- Illegal. > end Op_2; > end Q; > > Child packages in Ada provide the equivalent of friends in C++; thus, > the private part of a package is akin to protected in C++, with the > package body corresponding to C++'s private. There's one problem with this analogy. In C++, a class grants friendship status to other classes and/or functions. In Ada, a child package assumes friendship with the parent package whether the parent likes it or not.