comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Dynamich Dispatching...
Date: Mon, 4 Oct 2004 14:50:01 +0200
Date: 2004-10-04T14:50:01+02:00	[thread overview]
Message-ID: <uv6ftd235dgf$.1px68p9wf1tjb.dlg@40tude.net> (raw)
In-Reply-To: sa4wty64ugb.fsf@snoopy.apana.org.au

On Mon, 04 Oct 2004 21:02:44 +1000, Brian May wrote:

>>>>>> "Dmitry" == Dmitry A Kazakov <mailbox@dmitry-kazakov.de> writes:
> 
>     >> package Constructor is
>     >> function Create(Text: String; Radius: Integer) return Circle;
>     >> end Constructor ;
> 
>     Dmitry> You do not need a nested package here.
> 
> <URL:http://www.adahome.com/articles/1998-02/ar_lessons95.html>,
> section 1.4, recommends it. Actually, I don't understand why.

Yes, it indeed reads strange:

"If a class declares a function 'Create' returning an instance of a class,
all the child classes inherit that operation. This can be hazardous,
especially if the child class has more attributes than its parent (note: to
make programmers pay attention, the inherited function will be abstract
unless overridden). Indeed, the inherited 'Create' might not initialize
these attributes."

One *cannot* inherit Create, because, many tanks to Ada's designers,
functions are covariant in their results. Quick checks shows it:

package Foo is
   type X is tagged null record;
   function Create return X;
   
   type Y is new X with null record;
      -- Compile error, Y is not abstract,
      -- yet it does not override Create
end Foo;

One could treat Y's Create is as abstract, like in the quote, but where is
any danger? Let Y be abstract, then it may have no instances of its own!

Then if one really needs a contravariant result, then Create should be
class-wide. It is as simple as:

   function Create return X'Class;

One could use this variant for an object factory which decides which of
X'Class to create.

> There are other parts of this reference which seem dodgy though (at
> least to me), so I am not sure how much you can rely on it.
> 
> (Sections 1.2 and 7 really have me confused too).

Yes. I have an impression that the document reflects some preliminary
status of Ada.Finalization development. For example it talks about "void"
objects etc. Just a guess.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2004-10-04 12:50 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 [this message]
2004-10-15 18:27       ` Matthew Heaney
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