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,FREEMAIL_FROM,XPRIO autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,4a5bab72e3ac47fc,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!news.maxwell.syr.edu!feed.news.tiscali.de!newsfeed01.sul.t-online.de!newsmm00.sul.t-online.de!t-online.de!news.t-online.com!not-for-mail From: "Rick Santa-Cruz" Newsgroups: comp.lang.ada Subject: Dynamich Dispatching... Date: Sat, 2 Oct 2004 17:39:15 +0200 Organization: T-Online Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: news.t-online.com 1096731575 03 18781 nSYPXHYvh7rLSY9g 041002 15:39:35 X-Complaints-To: usenet-abuse@t-online.de X-ID: SCxLdiZ18emVogqyi44F5c8hFAE0O5k507m8ymw9KSL+o1k9H1bbcZ X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Original Xref: g2news1.google.com comp.lang.ada:4569 Date: 2004-10-02T17:39:15+02:00 List-Id: 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: -- package Objects package Objects is type Object is abstract tagged private; type Object_Ptr is access all Object'Class; procedure Draw(O: Object) is abstract; procedure Set_Text(O: in out Object; Text: String); function Get_Text(O: Object) return String; private type Object is abstract tagged record Text: String(1..50); end record; end Objects; package body Objects is procedure Set_Text(O: in out Object; Text: string) is begin O.Text(1..Text'Length) := Text; end Set_Text; function Get_Text(O: Object) return String is begin return O.Text; end Get_Text; end Objects; -- package Circles: with Objects; use Objects; package Circles is type Circle is new Object with private; procedure Draw(C: Circle); package Constructor is function Create(Text: String; Radius: Integer) return Circle; end Constructor ; private type Circle is new Object with record Radius: Integer; end record; end Circles; with Ada.Text_IO; use Ada.Text_IO; package body Circles is procedure Draw(C: Circle) is begin Put_Line("Circle: " & Get_Text(C) & Integer'Image(C.Radius)); end Draw; package body Constructor is function Create(Text: String; Radius: Integer) return Circle is C: Circle; begin Set_Text(C, Text); C.Radius := Radius; return C; end Create; end Constructor ; end Circles; -- main-procedure: with Ada.Text_IO; with Objects; with Circles; procedure Main is procedure Call_Dynamic(Object_Ptr: Objects.Object_Ptr) is begin Objects.Draw(Object_Ptr.all); end Call_Dynamic; C2: Circles.Circle; begin C2 := Circles.Constructor.Create("Circle1",50); Call_Dynamic(new Circles.Circle'(C2)); end Main; My question is now, why with Call_Dynamic I call the Draw-procedure in the package Circles, although in the body of Call_Dynamic I directly call the Method in the Objects Package? Surely it is syntactly correct, cause there is an abstract mehtod Draw in the Objects-Package, but I don't understand why such work with classes in different packages. I tested the same, when all classes are in the same package and surely it worked too, and for me and the understanding of dynamic-dispatching this is clear. How does this internally work with the different-package approach as described above in the source-code? Thanks in advance, Rick