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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!peer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!fx15.iad.POSTED!not-for-mail From: Shark8 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:30.0) Gecko/20100101 Thunderbird/30.0a1 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: A bad counterintuitive behaviour of Ada about OO References: <932kntuq5rrr.8sumwibqrufn.dlg@40tude.net> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <53dEv.527030$E36.206784@fx15.iad> X-Complaints-To: abuse@teranews.com NNTP-Posting-Date: Tue, 05 Aug 2014 22:40:01 UTC Organization: TeraNews.com Date: Tue, 05 Aug 2014 16:39:57 -0600 X-Received-Bytes: 3694 X-Received-Body-CRC: 2228841877 Xref: news.eternal-september.org comp.lang.ada:21471 Date: 2014-08-05T16:39:57-06:00 List-Id: On 05-Aug-14 15:07, Victor Porton wrote: > Pleas explain what exactly you mean saying "re-dispatch". The wiki-book has a pretty good explanation: http://en.wikibooks.org/wiki/Ada_Programming/Object_Orientation#Redispatching The difference between Dispatching and non-Dispatching is, essentially, the same as that of static- and dynamic-linking -- Re-Dispatching is when the dispatching-call makes another dispatching call. I'm probably not explaining it well but let's step-through -- given the following: Package Example is Type Base is tagged null record; Procedure Call_Op1 ( T1 : Base'Class ); -- A Dispatching Call Procedure Call_Op2 ( T1 : Base ); -- Not A Dispatching Call Procedure Operation ( T1 : Base ); -- Not A Dispatching Call Type Current is new Base with null record; Overriding Procedure Call_Op2 ( T1 : Current ); -- Not A Dispatching Call Overriding Procedure Operation( T1 : Current ); -- Not A Dispatching Call Type Child is new Current with null record; Overriding Procedure Call_Op2 ( T1 : Child ); -- Not A Dispatching Call Overriding Procedure Operation( T1 : Child ); -- Not A Dispatching Call End Example; Package Body Example is Procedure Call_Op1 ( T1 : Base'Class ) is begin T1.Operation; -- Re-Dispatching. end; Procedure Call_Op2 ( T1 : Base ) is begin Base'Class(T1).Operation; -- Dispatching end; Overriding Procedure Call_Op2 ( T1 : Current ) is begin Ada.Text_IO.Put_Line( "-- Current.Op2 --" ); Ada.Text_IO.Put( ASCII.HT ); Base'Class(T1).Operation; end; Overriding Procedure Call_Op2 ( T1 : Child ) is begin Ada.Text_IO.Put_Line( "-- Child.Op2 --" ); Ada.Text_IO.Put( ASCII.HT ); Base(T1).Call_Op2; end; Procedure Operation( T1 : Base ) is begin Ada.Text_IO.Put_Line( "-- BASE --" ); End Operation; Overriding Procedure Operation( T1 : Current ) is begin Ada.Text_IO.Put_Line( "-- CURRENT --" ); End Operation; Overriding Procedure Operation( T1 : Child ) is begin Ada.Text_IO.Put_Line( "-- CHILD --" ); End Operation; End Example; The execution of declare X : Example.Child; begin X.Call_Op1; X.Call_Op2; Example.Current(X).Operation; Example.Current(X).Call_Op1; Example.Current(X).Call_Op2; end; produces: -- CHILD -- -- Child.Op2 -- -- CHILD -- -- CURRENT -- -- CHILD -- -- Current.Op2 -- -- CHILD --