From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,4a5bab72e3ac47fc X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!proxad.net!newsfeed.stueberl.de!newsgate.cistron.nl!transit.news.xs4all.nl!195.241.76.212.MISMATCH!tiscali!transit1.news.tiscali.nl!dreader2.news.tiscali.nl!not-for-mail Newsgroups: comp.lang.ada Subject: Re: Dynamich Dispatching... References: From: Ludovic Brenta Date: Sun, 03 Oct 2004 20:56:17 +0200 Message-ID: <87zn33r5pq.fsf@insalien.org> User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) Cancel-Lock: sha1:+XLlRkhg2T+SrqrcI5Iore+fMTg= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Organization: Tiscali bv NNTP-Posting-Date: 03 Oct 2004 20:59:43 CEST NNTP-Posting-Host: 83.134.238.139 X-Trace: 1096829983 dreader2.news.tiscali.nl 44069 83.134.238.139:37726 X-Complaints-To: abuse@tiscali.nl Xref: g2news1.google.com comp.lang.ada:4618 Date: 2004-10-03T20:59:43+02:00 List-Id: "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.