comp.lang.ada
 help / color / mirror / Atom feed
From: Jim Rogers <jimmaureenrogers@worldnet.att.net>
Subject: Re: OO in Ada
Date: Sun, 06 Oct 2002 03:00:37 GMT
Date: 2002-10-06T03:00:37+00:00	[thread overview]
Message-ID: <3D9FA70C.1070407@worldnet.att.net> (raw)
In-Reply-To: h4Nn9.1864$UX4.1524@nwrddc04.gnilink.net

Hyman Rosen wrote:

> Jim Rogers wrote:
> 
>> I think that because the dispatching is always performed on the
>> type of "object" in object.method.
> 
> 
> Oh, I'm thinking of overloading on return type, sorry.
> There's no such thing as dispatching on return type, since
> by definition dispatching requires an object to dispatch
> upon!
> 
>> I disagree here. Ada does not give the illusion of multiple dispatch.
>> An Ada subprogram can only be primitive to one type.
> 
> 
> Yes, but that subprogram can take multiple parameters of that type,
> and when a call is made to that subprogram with arguments which are
> classwide, they must all have the same dynamic type (which is then
> used in the dispatch) or an exception results.


You are correct. There is a little more that needs to be said about
this.

Following is a quote from "Ada as a Second Language" 2nd Edition by
Norman Cohen (Section 12.4.4.3)

"At first glance, the requirement that all classwide parameters to a
dispatching call have the same tag may seem overly restrictive. There
are many operations in which it makes sense to manipulate two classwide
variables with different tags. Such an operation should be written as a
classwide subprogram - one with formal parameters explicitly declared to
be of a classwide type - rather than a dispatching program.

For example, the function Earlier_Than was declared in package Transactions
as follows:

    function Earlier_Than
     (Trans1, Trans2 : Transaction_Type'Class) return Boolean;

Because this function has two parameters of type Transaction_Type'Class, it
can be called with one operand that has a tag of Deposit_Type and another that
has the tag of Check_Type. The body of Earlier_Than simply compares the
Date_Part components of its operands, which are present in all
Transaction_Type'Class objects, so this is perfectly sensible. Had the function
been declared as

    function Earlier_Than
      (Trans1, Trans2 : Transaction_Type) return Boolean;

instead, it would have been a dispatching operation. Then a call on
Earlier_Than with two Transaction_Type'Class operands having the tag of
Deposit_Type would have dispatched to the version inherited by Deposit_Type,
and a call with two Transaction_Type'Class operands having the tag of
Check_Type would have dispatched to the (identical) version inherited
by Check_Type, but a call with Transaction_Type'Class operands having
different tags would have raised the exception Constriant_Error. This
would have made Earlier_Than useless for sorting a polymorphic array
of pointers to transactions."

The point being that this still follows the rule that a subprogram can
be primitive to only one type. If you need to call a program with
multiple tags belonging to a classwide hierarchy you must explicitly
create that subprogram, and it will not be a dispatching program.

Since this is not a dispatching subprogram there is no form of multiple
dispatch.

Jim Rogers






  reply	other threads:[~2002-10-06  3:00 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-04  2:14 OO in Ada Rick Duley
2002-10-04  2:55 ` Jim Rogers
2002-10-04 17:35   ` Hyman Rosen
2002-10-05  0:20     ` Jim Rogers
2002-10-05 23:38       ` Dmitry A.Kazakov
2002-10-05 15:25         ` Jim Rogers
2002-10-06 21:37           ` Dmitry A.Kazakov
2002-10-06  2:18       ` Hyman Rosen
2002-10-06  3:00         ` Jim Rogers [this message]
2002-10-08 21:08           ` Gisle Sælensminde
2002-10-04  3:37 ` Chad R. Meiners
2002-10-04  5:32 ` Simon Wright
2002-10-04  6:01 ` tmoran
2002-10-04 15:05 ` Matthew Heaney
2002-10-05  2:14 ` SteveD
2002-10-05  8:54   ` Preben Randhol
2002-10-07 14:10   ` Matthew Heaney
2002-10-07 19:52     ` Jeffrey Carter
2002-10-08 21:18     ` Dmitry A.Kazakov
2002-10-08  9:53 ` John McCabe
2002-10-08 15:37   ` Matthew Heaney
2002-10-08 16:47     ` Georg Bauhaus
2002-10-08 17:48       ` Matthew Heaney
2002-10-08 17:16     ` Warren W. Gay VE3WWG
2002-10-08 17:58       ` Matthew Heaney
2002-10-09 16:59         ` Warren W. Gay VE3WWG
2002-10-08 10:21 ` Preben Randhol
  -- strict thread matches above, loose matches on Subject: below --
1998-05-15  0:00 Gisle S{lensminde
replies disabled

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