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

I actually tried this, but it does not work.

The reason why myvisitor.execute(mynode) does not work is that at the point 
where this code is called the object you are dealing with is only known to 
be of class node.
At least in Java (and I believe also in C++), it is therefore always the 
"execute(Node n)" method of the visitor that is called, unless I introduce a 
cast, which I can not do without a switch statement, as I need to know where 
to cast to. Again, no matter what class "mynode" actually is, at the point 
of calling it is known to the runtime system only as a node, and therefore 
polymorphism fails.

If I use v.execute(this) inside of the subclass of node I want to use 
instead, it does work, because the language runtime actually types "this" 
appropriately - it knows now which class "this" actually means.


>From: "Joseph Kesselman" <keshlam@us.ibm.com>
>To: www-dom@w3.org
>Subject: Re: Type-safe iteration over the DOM in DOM 2 & 3?
>Date: Wed, 21 Mar 2001 16:08:12 -0500
>
>
> >accept(Visitor v)
> >{
> >    v.execute(this);
> >}
>
>I'm afraid I really don't see a meaningful difference, in that case,
>between calling mynode.accept(myvisitor)  and calling
>myvisitor.execute(mynode) directly. A difference only arises when accept()
>starts doing other things... and as I noted, the moment it does so you run
>into compatability problems between your visitors and visitees, and I don't
>see a way to define that cleanly at the API level.
>
>______________________________________
>Joe Kesselman  / IBM Research
>

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

Received on Thursday, 22 March 2001 01:24:21 UTC