comp.lang.ada
 help / color / mirror / Atom feed
From: dennison@telepath.com
Subject: Re: Help - Constructors - ASAP.
Date: 1998/07/31
Date: 1998-07-31T00:00:00+00:00	[thread overview]
Message-ID: <6psvnb$vkt$1@nnrp1.dejanews.com> (raw)
In-Reply-To: 35C1043E.9FFB23D0@elca-matrix.ch

In article <35C1043E.9FFB23D0@elca-matrix.ch>,
  Mats.Weber@elca-matrix.ch wrote:
> tedennison@my-dejanews.com wrote:
>
> > But what happens in the situation where the client (perhaps a different
> > developer) wants to make a child class with fields that *must* be
> > initialized? That seems a quite reasonable thing to do. But now the
> > class-wide "constructor" isn't valid anymore. It can still be called for
this
> > new child object, but will return a garbage value.
>
> That garbage value will be a value of the parent type, and assigning it to an
> object of the Child type, or to an object of type Child'Class, will raise
> Constraint_Error, so the problem will not go undetected. If your contructors
> are not class-wide and not primitive, then you detect the problem at compile
time.
>

I see. I thought you were somehow passing back an object of the right class
for the context.

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.

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.

If your worry was inheriting constructors when their parameter profile in no
longer viable for constructing a subclass, I can see part of your point. But I
think I'd rather just have said subclasses override the constructor with a
routine that applies sensible defaults (or raises Constraint_Error).

Hmm. I believe the language rules state that no more primitive operations may
be declared after the type is "finalized". It may be possible to force this by
doing something like deriving a dummy subclass before the constructor is
declared.

T.E.D.

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum




  reply	other threads:[~1998-07-31  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         ` Mats Weber
1998-07-31  0:00           ` dennison [this message]
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-07-31  0:00           ` Robert I. Eachus
1998-08-01  0:00             ` Matthew Heaney
1998-07-31  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