From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Protected types and visibility of their internals
Date: Tue, 8 Jul 2008 16:03:04 -0500
Date: 2008-07-08T16:03:04-05:00 [thread overview]
Message-ID: <g53jjv$mrr$1@jacob-sparre.dk> (raw)
In-Reply-To: b1f2203b-ed02-4031-bcba-40c0e1b1be07@j22g2000hsf.googlegroups.com
"Maciej Sobczak" <see.my.homepage@gmail.com> 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.
next prev parent reply other threads:[~2008-07-08 21:03 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-08 9:57 Protected types and visibility of their internals Maciej Sobczak
2008-07-08 12:52 ` Georg Bauhaus
2008-07-08 16:13 ` Robert A Duff
2008-07-09 7:53 ` christoph.grein
2008-07-08 21:03 ` Randy Brukardt [this message]
2008-07-10 21:49 ` Maciej Sobczak
2008-07-09 5:04 ` christoph.grein
2008-07-09 13:44 ` Maciej Sobczak
2008-07-09 15:12 ` Adam Beneschan
2008-07-09 22:19 ` Stephen Leake
2008-07-09 22:38 ` Adam Beneschan
2008-07-10 0:18 ` Randy Brukardt
2008-07-10 0:18 ` Randy Brukardt
2008-07-09 23:22 ` jimmaureenrogers
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox