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,LOTS_OF_MONEY autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,c7a5c447f88aecaa X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-11-28 12:09:52 PST Path: archiver1.google.com!news1.google.com!sn-xit-02!sn-post-01!supernews.com!corp.supernews.com!not-for-mail From: "Matthew Heaney" Newsgroups: comp.lang.ada Subject: Re: Pre-Elaboration clarification. Date: Wed, 28 Nov 2001 15:13:34 -0500 Organization: Posted via Supernews, http://www.supernews.com Message-ID: References: X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4807.1700 X-Complaints-To: newsabuse@supernews.com Xref: archiver1.google.com comp.lang.ada:17130 Date: 2001-11-28T15:13:34-05:00 List-Id: "Mark Lundquist" wrote in message news:fiaN7.89348$XJ4.48897553@news1.sttln1.wa.home.com... > - If only the body needs the type, then put it in the body. Or in the spec of a private child. > - If code in other (non-child) packages depends on it, but only the compiler > (not the code) needs to know the representation, then put the full > definition in the private part. > - If the only things depending on the type are other types in the private > part, there is no need for a private_type_declaration (that is, "is private" > in the public part). Define the type in the private part but don't mention > it in the public part. > - If the code in other (non-child) packages needs to see it, put it in the > public part of the spec > > I wrote the cases in order from most- to least- encapsulated, because it's > good to get in the habit of thinking that way. Other techniques include: o if only a pointer to the type is required, then you can defer the rep to the body: package P is type Handle is private; private type Rep; type Handle is access Rep; end P; packge body P is type Rep is null record; --or whatever end P; o sometimes it makes sense to declare an abstract interface, and then provide a constructor for it: package P is pragma Elaborate_Body; type T is abstract tagged null record; procedure Op (O : access T) is abstract; type T_Class_Access is access all T'Class; end P; --the "constructor" --you could declare this in P, but then you won't be --able to use a categorization pragma. function P.New_T return T_Class_Access; private package P.C is type Rep is new T with null record; --or whatever procedure Op (O : access Rep); end P.C; with P.C; function P.New_T return T_Class_Access is begin return new P.C.Rep; end; In this way, you're able to hide all kinds of dependencies, because a client only manipulates type P.T'Class. This is essentially what Lakos described as a "protocol class." We could talk all day about this stuff, which is what I intend to do at next years Ada-Europe conference in Vienna.