comp.lang.ada
 help / color / mirror / Atom feed
From: dmitry@elros.cbb-automation.de (Dmitry A. Kazakov)
Subject: Re: Merits of re-dispatching [LONG]
Date: Tue, 12 Feb 2002 09:02:27 GMT
Date: 2002-02-12T09:02:27+00:00	[thread overview]
Message-ID: <3c68d3ce.90025781@News.CIS.DFN.DE> (raw)
In-Reply-To: u68q8fc9t4qt1c@corp.supernews.com

On Fri, 8 Feb 2002 18:51:00 -0500, "Matthew Heaney" <mheaney@on2.com>
wrote:

>"Dmitry A. Kazakov" <dmitry@elros.cbb-automation.de> 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 <something> 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



  reply	other threads:[~2002-02-12  9:02 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-02-07 10:26 Merits of re-dispatching [LONG] Dmitry A. Kazakov
2002-02-07 15:03 ` Hyman Rosen
2002-02-08  1:29   ` Matthew Heaney
2002-02-08  9:16     ` Dmitry A. Kazakov
2002-02-08 18:30       ` Hyman Rosen
2002-02-09  0:10         ` Matthew Heaney
2002-02-12  8:32         ` Dmitry A. Kazakov
2002-02-12 21:37           ` Hyman Rosen
2002-02-13  9:29             ` Dmitry A. Kazakov
2002-02-13 14:32               ` Hyman Rosen
2002-02-13 19:58           ` Dave Harris
2002-02-14 15:06             ` Dmitry A. Kazakov
2002-02-16 12:10               ` Dave Harris
2002-02-18  8:57                 ` Dmitry A. Kazakov
2002-02-18 19:47                   ` Merits of re-dispatching Dave Harris
2002-02-19  9:20                     ` Dmitry A. Kazakov
2002-02-21  5:49                       ` Hyman Rosen
2002-02-21  9:04                         ` Dmitry A. Kazakov
2002-02-21 18:17                           ` Hyman Rosen
2002-02-22  9:21                             ` Dmitry A. Kazakov
2002-02-22 16:59                               ` Hyman Rosen
2002-02-25  8:51                                 ` Dmitry A. Kazakov
2002-02-08 23:51       ` Merits of re-dispatching [LONG] Matthew Heaney
2002-02-12  9:02         ` Dmitry A. Kazakov [this message]
2002-02-07 23:40 ` Nick Roberts
2002-02-08  8:56   ` Dmitry A. Kazakov
2002-02-08  1:06 ` Matthew Heaney
2002-02-08  9:48   ` Dmitry A. Kazakov
2002-02-09  0:16     ` Matthew Heaney
2002-02-08 18:10   ` Hyman Rosen
2002-02-09  0:41     ` Matthew Heaney
2002-02-08 18:33 ` Nick Roberts
2002-02-09  4:07   ` Nick Roberts
2002-02-12 10:13   ` Dmitry A. Kazakov
2002-02-14 20:57 ` Tucker Taft
2002-02-15 15:43   ` Dmitry A. Kazakov
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox