Re: Type-safe iteration over the DOM in DOM 2 & 3?

I do stand corrected and apologize.

Enclosed you find a version in C++ and Java that works...

Output:
C:\Visitors>java VisitorA
executing on a generic Node
executing on a NodeX

The problem with your version (and at the same time with my previous 
argument) is that the base class/interface for the visitor MUST have all 
versions of execute defined in order to work, no matter if the second 
dispatch is done using different function names or same function names with 
just different argument types.

It is still a working dual-dispatch, as argued before, but for the purpose 
of a general interface this issue makes it less practical as the base 
interface Visitor needs to be modified to contain all subclasses to be 
called. Just extending the interface with new execute methods for the new 
subclasses won't do, at least in Java.




BTW, the difference between your java version and mine is:
interface Visitor
{
    public void execute(Node n);
    public void execute(NodeX n);   <--- Needs to be defined in base IF
}





>From: James Melton <james.melton@cylogix.com>
>To: Peter Meyer <petermeyer99@hotmail.com>
>Subject: Re: Type-safe iteration over the DOM in DOM 2 & 3?
>Date: Thu, 22 Mar 2001 13:19:09 -0500
>
>I have already tested this and come to my previous conclusion. Attached
>are the files I used to test.
>
>Here is my output:
>   $ java VisitorA
>   executing on a generic Node
>   executing on a generic Node
>
>Here is the java version I'm using:
>   $ java -version
>   java version "1.2.2"
>   Solaris VM (build Solaris_JDK_1.2.2_05, native threads, sunwjit)
>
>Hope this clarifies the discrepancy we see.
>Jim.
>
>
>Peter Meyer wrote:
> >
> > James,
> > what you write is, to my best knowledge, simply not correct.
> >
> > First of all, the example I gave you works fine even with overloaded 
>visit
> > methods (please givue it a try), and secondly, there is a double 
>dispatch
> > happening in exactly the sense of the section of the GoF book you cite.
> >
>
>____________________________________________________________
>James Melton                 CyLogix
>609.750.5190                 609.750.5100
>james.melton@cylogix.com     www.cylogix.com
><< Visitor.zip >>

_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

Received on Thursday, 22 March 2001 15:06:44 UTC