From: "Matthew Heaney" <mheaney@on2.com>
Subject: Re: Pre-Elaboration clarification.
Date: Wed, 28 Nov 2001 15:13:34 -0500
Date: 2001-11-28T15:13:34-05:00 [thread overview]
Message-ID: <u0ah4e2d38je97@corp.supernews.com> (raw)
In-Reply-To: fiaN7.89348$XJ4.48897553@news1.sttln1.wa.home.com
"Mark Lundquist" <up.yerz@nospam.com> 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.
next prev parent reply other threads:[~2001-11-28 20:13 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-11-05 15:52 Pre-Elaboration clarification Clueless
2001-11-05 17:49 ` Jeffrey Carter
2001-11-09 22:45 ` Matthew Heaney
2001-11-22 15:46 ` Clueless
2001-11-28 17:55 ` Matthew Heaney
2001-11-28 18:12 ` WAS " Mark Lundquist
2001-11-28 18:46 ` Mark Lundquist
2001-11-28 20:13 ` Matthew Heaney [this message]
2001-11-29 9:34 ` Simon Wright
2001-11-10 6:31 ` Robert Dewar
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox