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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,ff6dd65dff421bcf X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news2.google.com!proxad.net!fr.ip.ndsoftware.net!news.netcologne.de!newsfeed-fusi.netcologne.de!151.189.20.20.MISMATCH!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Protected types private part visibility , helpfull hints needed. Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.14.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: Date: Thu, 28 Apr 2005 14:16:56 +0200 Message-ID: <3ecghis18u1q$.dxtujoestjq.dlg@40tude.net> NNTP-Posting-Date: 28 Apr 2005 14:16:56 MEST NNTP-Posting-Host: cc9fc6f5.newsread2.arcor-online.net X-Trace: DXC=dI];e`[\1P>::C@ZGckeZ1Q5U85hF6f;4jW\KbG]kaM8:cmYYm_h3\3nL]o^6FWH;6WRXZ37ga[7:n919Q4_`Vj9B8=X\UUgbk4 X-Complaints-To: abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:10778 Date: 2005-04-28T14:16:56+02:00 List-Id: On Thu, 28 Apr 2005 13:30:12 +0200, Christopher Gosset wrote: > I am making a library consisting of several packages. > I wished to make all memory management and other "house-holding" > functions private by having them in private packages and to make all > details that is not a part of the "client-view" private. > > So I have a package spec with a protected type that look something like > this > > Generic > Type Item_Type (<>) is Private ; > > Package Protected_List is > > Protected Type List is > > Procedure Add( Item : In Item_Type) ; > Function Item(Index : In Positive) Return Item_Type ; > > Private > > Internal_List_Structure : Internal_List ; ----------< > This is the problem line I would like the internal list structure to be > declared in a PRIVATE package and be visible to this private part >>------- > > End List ; > > Private > Type Item_Pointer is Access Item_Type ; > > End Protected_List ; > > This does not work! This is because the Private part of the Protected > Type Declaration is a PART OF THE PUBLIC PART OF THE PACKAGE SPEC ! It is only nominally there. > Is there a reason behind this design? Well, protected and task types break Ada's design which otherwise carefully separates scopes and types. For both there are reasons why. As for protected types, their members need to be safe(protected) from any access other than through the operations of the type. The visibility here is simply not determined by the enclosing package. If you want something comparable then consider it is as a nested package. You can't access its private part from outside (except from children of course.) Maybe it would be better to have protected objects and packages instead of objects and types. > Wouldn't it be more reasonable > that the private part of a Protected Type should be a part of the > PRIVATE part of the package spec and thus be able to use types and > procedures declared in private packages and private parts of the parent > ? It would be reasonable for all record-like types to have private members (declared in the private package part.) Presently only non-primitive operations can be made private. Abstract primitive operations and entry points cannot be. > The private part of the protected type should never be visible to the > client anyway and the fact that all types and pakcages used in the > protected type private part must be Public destroys my absctraction! There are also numerous other cases. For example: the default value of a parameter cannot be hidden. Tagged type cannot be extended by adding both public and private members etc. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de