comp.lang.ada
 help / color / mirror / Atom feed
From: Ludovic Brenta <ludovic.brenta@insalien.org>
Subject: Re: Dynamich Dispatching...
Date: Sun, 03 Oct 2004 20:56:17 +0200
Date: 2004-10-03T20:59:43+02:00	[thread overview]
Message-ID: <87zn33r5pq.fsf@insalien.org> (raw)
In-Reply-To: cjmi3n$iat$03$1@news.t-online.com

"Rick Santa-Cruz" writes:
> Hi,
>
> I know what to understand about Dynamic Dispatching, but with the
> following example in Ada I have some problems to understand the
> whole thing:

RM 3.9.2(20, 21) state that the only factor that determines which
subprogram (method) is called is the tag of the operand (i.e. the
actual run-time type).  Whether or not the subprogram is visible at
the point of call is irrelevant.  Thus:

package Objects is
   type Object is tagged private;
   procedure Draw (O : in Object); -- a primitive suprogram
   procedure Draw_Any (O : in Object'Class); -- not a primitive
private ...
end Objects;

package body Objects is
   ...
   procedure Draw_Any (O : in Object'Class) is
   begin
      Draw (O); -- dynamic dispatching call
   end Draw_Any;
end Objects;

with Objects;
package Circles is
   type Circle is new Objects.Object with private;
   procedure Draw (C : in Circle); -- overrides Objects.Draw
private ...
end Circles; 

with Circles;
with Objects;
procedure Main is
   C : Circles.Circle;
begin
   Objects.Draw_Any (C);
end Main;

Even though the procedure Draw_Any does not see the package Circles,
dynamic dispatching still causes Circles.Draw to be called.  This is
good; it means that Draw_Any does not have to be aware of the
existence of all types derived from Objects.Object.  This in turns
means that new derived types can be added to the program without
changing Draw_Any.

-- 
Ludovic Brenta.



  parent reply	other threads:[~2004-10-03 18:56 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 [this message]
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
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