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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,d4e2f238dc61c890 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!club-internet.fr!feedme-small.clubint.net!nuzba.szn.dk!news.jacob-sparre.dk!pnx.dk!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Protected types and visibility of their internals Date: Tue, 8 Jul 2008 16:03:04 -0500 Organization: Jacob's private Usenet server Message-ID: References: NNTP-Posting-Host: static-69-95-181-76.mad.choiceone.net X-Trace: jacob-sparre.dk 1215648191 23419 69.95.181.76 (10 Jul 2008 00:03:11 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Thu, 10 Jul 2008 00:03:11 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5512 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512 Xref: g2news1.google.com comp.lang.ada:1064 Date: 2008-07-08T16:03:04-05:00 List-Id: "Maciej Sobczak" wrote in message news:b1f2203b-ed02-4031-bcba-40c0e1b1be07@j22g2000hsf.googlegroups.com... > Consider a protected type in some package: > > package P is > protected type PT is > procedure Foo; > private > X : Some_Type; > end PT; > end P; > > The protected type has a component X of Some_Type, which is entirely > the private business of the protected type. > > Where this type should be declared? I think you are asking the wrong question. The question is "Where should the protected type be declared?". Since there are no operations that are specific to protected types, there is very little reason to make those a visible type. Thus, I would generally structure the package with a private type and the protected type (if any) declared in the private part. Something like: package P2 is type Priv is tagged limited private; procedure Foo (Obj : in out Priv); private type Some_Type is ... protected type PT is procedure Foo; private X : Some_Type; end PT; type Priv is tagged limited record Lock : PT; end record; end P2; This structure works well because it is always important to make the protected portion of the operation as short as possible, and this layout allows a place to do things that don't need mutual exclusion. There is an alternative if you really need access to the protected object directly, which is to declare a protected interface in the visible part of the package and then derive the protected type from it in the private part. Either way, you will find that you put most of your declarations in the private part. It's not unusual for the majority of the code of a package specification to be in the private part. Randy.