comp.lang.ada
 help / color / mirror / Atom feed
From: Matthew Heaney <matthew_heaney@acm.org>
Subject: Re: Help - Constructors - ASAP.
Date: 1998/08/01
Date: 1998-08-01T00:00:00+00:00	[thread overview]
Message-ID: <m31zr1wvo1.fsf@mheaney.ni.net> (raw)
In-Reply-To: 6psvnb$vkt$1@nnrp1.dejanews.com

dennison@telepath.com writes:

> 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 you don't like returning the class-wide type, then declare a
constructor that returns the specific type, but is not primitive.  The
simplest way to do this is to declare the constructors in a nested
package:

package P is

   type T is tagged private;

   <primitive ops>

   package Constructors is

      function New_T (I : Integer) return T;

   end Constructors;

private
...
end P;


> 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.

You can detect type mismatches at compile-time by using a constructor
that returns the specific type (not the class-wide type), and is
non-primitive.  See the example above.

> 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.

I'm not sure what you mean.  If you want non-primitive operations, then
just declare them in a nested package.  Don't use the freezing rules
(see RM95 13.14) to try to do this; that would be confusing.





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