From: Mats Weber <Mats.Weber@elca-matrix.ch>
Subject: Re: Help - Constructors - ASAP.
Date: 1998/08/03
Date: 1998-08-03T00:00:00+00:00 [thread overview]
Message-ID: <35C5CA85.85DDB431@elca-matrix.ch> (raw)
In-Reply-To: 6psvnb$vkt$1@nnrp1.dejanews.com
dennison@telepath.com wrote:
> I see. I thought you were somehow passing back an object of the right class
> for the context.
No, because you can't do this.
package Parent is
type T is tagged private;
function Construct return T'Class;
-- Class-wide just to make it non-primitive.
end Parent;
with Parent;
package Child is
type T is new Parent.T with private;
end Child;
As Parent has no knowledge of Child, its constructure cannot be modified to
return a Child.T. It will always return a Parent.T, which will raise
Constraint_Error in the following case:
declare
X : Child.T := Parent.Construct;
begin
...
> But, a naieve reader would look at that and think that they could get back an
> object of *any* type in the class (as I have just proven :-) ), when in
> actuality they always get back the same class of object.
This means that you should not mess with tagged types as long as you are still
naive :-)
> If I read you correctly, what you were worried about was developers screwing
> up and forgetting to override the default constructors. Nothing about this
> solution prevents that. Now instead of getting the default constructor, our
> hapless client will compile with the class-wide constructor. They get an
> exception at runtime either way. But now the client, who is just as capable
> of screwing up as the subclass author, could goof and use the class-wide
> constructor on his own.
This seems to show that non-primitive _and_ non class-wide constructors are
preferable (e.g. using the nested package or child package approach).
next prev parent reply other threads:[~1998-08-03 0:00 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-07-23 0:00 Help - Constructors - ASAP Maxim Senin
1998-07-26 0:00 ` Matthew Heaney
1998-07-27 0:00 ` dennison
1998-07-30 0:00 ` Robert I. Eachus
1998-07-30 0:00 ` tedennison
1998-07-31 0:00 ` Matthew Heaney
1998-07-31 0:00 ` Mats Weber
1998-07-31 0:00 ` dennison
1998-08-01 0:00 ` Robert Dewar
1998-08-01 0:00 ` Matthew Heaney
1998-08-01 0:00 ` Matthew Heaney
1998-08-03 0:00 ` Mats Weber [this message]
1998-07-31 0:00 ` Robert I. Eachus
1998-08-01 0:00 ` Matthew Heaney
1998-08-01 0:00 ` Robert Dewar
1998-08-01 0:00 ` Matthew Heaney
1998-08-03 0:00 ` Mats Weber
1998-08-03 0:00 ` Matthew Heaney
1998-08-03 0:00 ` Mats Weber
1998-08-04 0:00 ` Matthew Heaney
1998-08-04 0:00 ` Mats Weber
1998-08-05 0:00 ` Matthew Heaney
1998-08-10 0:00 ` Robert I. Eachus
1998-08-03 0:00 ` tedennison
-- strict thread matches above, loose matches on Subject: below --
1998-07-15 0:00 Maxim Senin
1998-07-16 0:00 ` Stephen Leake
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox