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,c9a5d6b3975624e1 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-10-05 20:00:37 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!arclight.uoregon.edu!wn4feed!worldnet.att.net!bgtnsc04-news.ops.worldnet.att.net.POSTED!not-for-mail Message-ID: <3D9FA70C.1070407@worldnet.att.net> From: Jim Rogers User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:0.9.4) Gecko/20011128 Netscape6/6.2.1 X-Accept-Language: en-us MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: OO in Ada References: <3D9D02F3.9090600@worldnet.att.net> <1033752899.224298@master.nyc.kbcfp.com> <3D9E3018.8000403@worldnet.att.net> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Date: Sun, 06 Oct 2002 03:00:37 GMT NNTP-Posting-Host: 12.86.38.13 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc04-news.ops.worldnet.att.net 1033873237 12.86.38.13 (Sun, 06 Oct 2002 03:00:37 GMT) NNTP-Posting-Date: Sun, 06 Oct 2002 03:00:37 GMT Organization: AT&T Worldnet Xref: archiver1.google.com comp.lang.ada:29538 Date: 2002-10-06T03:00:37+00:00 List-Id: 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