From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: What makes a procedure call 'dispatching' in Ada?
Date: Fri, 20 Nov 2009 15:56:50 +0200
Date: 2009-11-20T15:56:50+02:00 [thread overview]
Message-ID: <4b06a048$0$26319$4f793bc4@news.tdc.fi> (raw)
In-Reply-To: <he64pl$d8i$1@nntp.ilk.net>
Markus Schoepflin wrote:
> Hello,
>
> I'm trying to fell may way around object oriented Ada programming, and I
> think I must be missing something absolutely basic. Please consider the
> following package:
>
> ---%<---
> package FOOS is
>
> type FOO is abstract tagged null record;
>
> procedure P (THIS : in FOO);
> procedure A (THIS : in FOO) is abstract;
>
> end FOOS;
No problems there (well, Dmitry will have philosophical objections to
this design :-)
> package body FOOS is
>
> procedure P (THIS : in FOO)
> is
> begin
> A (THIS);
At this point, the compiler knows that THIS is a FOO object, or is to be
seen as a FOO object. But you have said that the procedure A on FOO is
abstract -- not implemented -- so you cannot call it.
I assume that your intention is to call the procedure A that is
implemented (overriden) for the actual object THIS, which is of some
type derived from FOO .. some type in FOO'Class for which you have
implemented A. To do so, you must ask the compiler to make this call
dispatching, by converting the parameter to FOO'Class:
A (FOO'Class (THIS));
This is called a "redispatching" call, because the procedure P may have
been reached as the result of a dispatching call on P, and now we are
asking to dispatch again.
One way to understand this is that in Ada by default calls are
statically bound, not run-time bound (dispatching). Only calls that have
parameters of class type are dispatching.
Dmitry has philosophical objections to redispatching, which is why he
suggests that you should declare P with a class-type parameter THIS in
the first place, so that A (THIS) will dispatch. Either will work, but
in Dmitry's approach you cannot override P for derived types, because it
is then a class-wide operation, not a primitive operation of FOO. In
both approaches you can override A for derived types (and you must
override it because it is abstract in FOO).
--
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
. @ .
next prev parent reply other threads:[~2009-11-20 13:56 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-20 13:15 What makes a procedure call 'dispatching' in Ada? Markus Schoepflin
2009-11-20 9:31 ` stefan-lucks
2009-11-20 14:10 ` Niklas Holsti
2009-11-20 13:27 ` Dmitry A. Kazakov
2009-11-20 13:43 ` Markus Schoepflin
2009-11-20 13:54 ` RasikaSrinivasan@gmail.com
2009-11-20 13:58 ` Markus Schoepflin
2009-11-20 14:19 ` Niklas Holsti
2009-11-21 14:07 ` Peter C. Chapin
2009-11-20 14:00 ` Niklas Holsti
2009-11-20 14:10 ` Dmitry A. Kazakov
2009-11-20 13:56 ` Niklas Holsti [this message]
2009-11-20 14:31 ` Dmitry A. Kazakov
2009-11-20 15:00 ` Niklas Holsti
2009-11-20 18:44 ` Dmitry A. Kazakov
2009-11-20 20:09 ` Niklas Holsti
2009-11-20 20:59 ` Dmitry A. Kazakov
2009-11-20 14:54 ` Ludovic Brenta
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox