comp.lang.ada
 help / color / mirror / Atom feed
From: "Matthew Heaney" <mheaney@on2.com>
Subject: Re: Dynamich Dispatching...
Date: Fri, 15 Oct 2004 14:27:12 -0400
Date: 2004-10-15T18:15:05+00:00	[thread overview]
Message-ID: <417013a9$0$91009$39cecf19@news.twtelecom.net> (raw)
In-Reply-To: uv6ftd235dgf$.1px68p9wf1tjb.dlg@40tude.net


"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
news:uv6ftd235dgf$.1px68p9wf1tjb.dlg@40tude.net...
> On Mon, 04 Oct 2004 21:02:44 +1000, Brian May wrote:
>
> Then if one really needs a contravariant result, then Create should be
> class-wide. It is as simple as:
>
>    function Create return X'Class;

The issue is not whether one needs a contravariant result.  Rather, the
issue is whether the constructor is primitive for the type or not.

In general, constructors should *not* be primitive.  One way to do that is
to declare the constructor in a nested package:

package P is
   type X is tagged ...;
   package Constructors is
      function Create return X;
   end;
end P;

A constructor should always return a specific type, not a class-wide type.
Your example above is wrong, since it would require the declaration of an
object whose type is class-wide, and hence force the use of dispatching.
Clearly that's wrong, when you know the specific type of object you want to
create.

The only time is makes sense for a constructor to return a class-wide type
is when this is a factory method pattern.  In that case, the operation is
primitive for parameter type:

package Q is
   type X is abstract tagged ...;
   type Y is abstract tagged ...;

   function Create (O : X) return Y'Class is abstract;
end Q;






  reply	other threads:[~2004-10-15 18:27 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-02 15:39 Dynamich Dispatching Rick Santa-Cruz
2004-10-03 17:11 ` Martin Krischik
2004-10-03 22:59   ` Brian May
2004-10-04  8:22     ` Martin Krischik
2004-10-03 18:56 ` Ludovic Brenta
2004-10-04  4:45   ` Jeffrey Carter
2004-10-04 21:01     ` Ludovic Brenta
2004-10-05  0:32       ` Jeffrey Carter
2004-10-04  8:02 ` Dmitry A. Kazakov
2004-10-04 11:02   ` Brian May
2004-10-04 12:50     ` Dmitry A. Kazakov
2004-10-15 18:27       ` Matthew Heaney [this message]
2004-10-16 19:25         ` Dmitry A. Kazakov
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox