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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,7ee10ec601726fbf X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-10-31 08:23:39 PST Path: archiver1.google.com!news2.google.com!news1.google.com!newsfeed.stanford.edu!sn-xit-01!sn-post-01!supernews.com!corp.supernews.com!not-for-mail From: "Matthew Heaney" Newsgroups: comp.lang.ada Subject: Re: Questions - Polimorphism/Dynamic Binding Date: Wed, 31 Oct 2001 11:26:45 -0500 Organization: Posted via Supernews, http://www.supernews.com Message-ID: References: X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4807.1700 X-Complaints-To: newsabuse@supernews.com Xref: archiver1.google.com comp.lang.ada:15487 Date: 2001-10-31T11:26:45-05:00 List-Id: "Eric Merritt" wrote in message news:mailman.1004543264.20599.comp.lang.ada@ada.eu.org... > > The whole point of an interface type is that you > > have some operation that > > operates on any object that conforms to that > > interface, for example: [original code snipped] Actually, the original code wasn't quite correct. I should have done this (again, I haven't tried compiling this): package P is type IT is abstract tagged limited null record; type IT_Class_Access is access all IT'Class; for IT_Class_Access'Storage_Size use 0; procedure Op (O : access IT) is abstract; end P; with P; package Q is type T is limited private; function IT_View (O : access T) return P.IT_Class_Access; ... private type IT_View_Type (T_Part : access T) is new P.IT with null record; procedure Op (O : access IT_View_Type); type T is limited record IT_View : aliased IT_View_Type (T'Access); ... end record; end Q; package body Q is function IT_View (O : access T) return P.IT_Class_Access is begin return O.IT_View'Access; end; procedure Op (O : access IT_View_Type) is T_Part : T renames O.T_Part.all; begin --do something to T_Part end; end Q; Now, suppose you have an operation that operates on objects that conform to the interface type: procedure Do_Something (O : access P.IT'Class); Using this schema, we can pass objects of type Q.T to Do_Something: declare O : aliased Q.T; begin Do_Something (IT_View (O'Access)); end; > Once again, this may be a bit of a stupid question but > I need to get this strait in my mind. > In this instance does O.I have access to O? Yes, through its access discriminant. The interface object, of type IT_View_Type, binds to the "current instance" of type T. The implementation of Op (which takes an access to IT_View_Type parameter) can see rest of the object through its descriminant (here, T_Part). (This technique is not unlike passing a "this" pointer to a ctor in C++.) > Or more > specifically, how will the procedure Do_Something get > access to the object properties which are actually > stored in record O not O.I? Somehow I get the feeling > I am missing something fairly important here. Thank > you for your time. Well of course Do_Something doesn't know anything about Q.T -- it only knows that the object conforms to the interface specified for type P.IT (specifically, that it has an Op operation). The implementation of Do_Something would look something like: procedure Do_Something (O : access P.IT'Class) is begin ... Op (O); --dispatches ... end; But perhaps you really meant how to implement Op? See above.