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,7a180be12347b9d3 X-Google-Attributes: gid103376,public X-Google-Thread: 1108a1,7a180be12347b9d3 X-Google-Attributes: gid1108a1,public X-Google-ArrivalTime: 2002-02-12 01:00:09 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsfeeds.belnet.be!news.belnet.be!uni-erlangen.de!fu-berlin.de!uni-berlin.de!tar-alcarin.cbb-automation.DE!not-for-mail From: dmitry@elros.cbb-automation.de (Dmitry A. Kazakov) Newsgroups: comp.lang.ada,comp.object Subject: Re: Merits of re-dispatching [LONG] Date: Tue, 12 Feb 2002 09:02:27 GMT Message-ID: <3c68d3ce.90025781@News.CIS.DFN.DE> References: <3c62524f.93369796@News.CIS.DFN.DE> <1013094178.985786@master.nyc.kbcfp.com> <3c6392e8.2400843@News.CIS.DFN.DE> NNTP-Posting-Host: tar-alcarin.cbb-automation.de (212.79.194.111) X-Trace: fu-berlin.de 1013504405 48208543 212.79.194.111 (16 [77047]) X-Newsreader: Forte Free Agent 1.21/32.243 Xref: archiver1.google.com comp.lang.ada:19909 comp.object:34177 Date: 2002-02-12T09:02:27+00:00 List-Id: On Fri, 8 Feb 2002 18:51:00 -0500, "Matthew Heaney" wrote: >"Dmitry A. Kazakov" wrote in message >news:3c6392e8.2400843@News.CIS.DFN.DE... > > The reason why C++ dispatches in B::f (), is that otherwise it would >> impossible to have class wide subroutines [see the point 1]. In >> contrary to this Ada 95 does have class wide routines, so my question, >> why [explicit] re-dispatching is supported in Ada 95? > >Because you may want to let a derived type override the algorithm in the >parent type. > >A class-wide operation typically declares an overall algorithm, and >dispatching is used to provide the details: > >package P is > type T is tagged limited null record; > procedure Op1 (O : T); > procedure Op2 (O : T); > procedure Op (O : T'Class); >end P; > >package body P is > procedure Op (O : T'Class) is --static > begin > if then > Op1 (O); --dynamic > else > Op2 (O); --dynamic > end if; > end Op; >... >end P; > >This is fine, but if you want to change the algorithm used by class-wide >operation Op, you can't. And this is good, because a class-wide operation is not defined for the root type. It is defined for the closure of all types derived from the root. Thus it cannot be overriden. It is a progam design flaw if you need to do so. What you want is actually multiple implementations, but this is not the realm of class-wided routines, but of dispatching ones. Consider class-wide routines as an [good] alternative to generic routines. You cannot override a generic routine, you can only overload it. Purely theoretically it is thinkable to build a type system with one additional type level: class-class-wide type. Then one could have an ability to dispatch on class-wide routines: procedure MetaOp (O : T'Class'Class) is begin Op (O); -- Meta dispatch end MetaOp; Though I do not think that such thing will appear in Ada very soon (:-)) >In general, an operation --primitive or class-wide-- should document which >dispatching operations it calls, so that a derived type knows what is >expected of it. It is a maintenace disaster. Though LSP cannot be enforced, one should support it as much as possible. However, my point was that the language should not support re-dispatching. If a programmer want it he/she must do some work, for instance, add a type identification member. It is very similar to the Unchecked_Conversion case. Regards, Dmitry Kazakov