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-30 14:24:50 PST Path: archiver1.google.com!news1.google.com!sn-xit-02!sn-post-02!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: Tue, 30 Oct 2001 17:28:02 -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:15439 Date: 2001-10-30T17:28:02-05:00 List-Id: "Eric Merritt" wrote in message news:mailman.1004456694.3472.comp.lang.ada@ada.eu.org... > I started out in Java and C++ and recently found the > one true langauge (Ada95, lol). In any case, one thing > that I found very usefull in Java was the Interface. I > don't believe that Ada has this at all. I was > wondering if there is a way to impliment this type of > functionality in Ada Not directly. For now the closest thing you can do is use the "multiple views" idiom. Suppose you have an "interface" type: package P is type T is tagged limited null record; procedure Op (O : in out T) is abstract; end P; Now what we want is to have a tagged type that "conforms" to this interface. One way to do this is like this (I haven't tried compiling this, but you'll get the idea): with P; package Q is type T_Public; type TI is new P.T (O : access T_Public) with null record; procedure Op (O : in out TI); type T_Public is abstract tagged limited record I : aliased TI; end record; type T is new T_Public with private; procedure Op2 (O : in T); ... end Q; This idea is that if you have an object of type T, then you can either view it as a T, or use its (public) I component to view it as the interface type P.T: declare O : Q.T; begin Op2 (O); --view as a Q.T Op (O.I); --view as "interface" P.T end; The interface part of T (its component I) can view the outer type through its access discriminant. > If you have a tagged type and extend that type with a > new type. package P is type T is limited null record; procedure Op (O : in out T); end; package P.C is type NT is new T with null record; procedure Op (O : in out NT); end; > Then pass the new type to a procedure that > accepts its the new types parent, the original type. Hmmm... Is the call static or dynamically bound? Do you mean: declare O : P.C.NT; begin P.Op (O); --? end; I don't think this will compile (this is a statically bound call), because procedure P.Op takes type P.T, not P.C.NT. > Are procedures associated with the child type > (methods) that override it's parent types procedures > called in this instance, even though the procedure > that this type is passed into is unaware of the new > child type and has not withed it's package? Not sure what you mean. The correct procedure will always get called in a dispatching (dynamically bound) call: declare O : P.T'Class := P.C.NT'(null record); --check my syntax begin Op (O); --try P.Op and P.C.Op and see how your compiler reacts end; Here, P.C.Op will get called, because O's tag has the value P.C.NT. Or where you expecting something else?