W3C home > Mailing lists > Public > www-dom@w3.org > January to March 2001

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

From: Peter Meyer <petermeyer99@hotmail.com>
Date: Thu, 22 Mar 2001 06:23:46 -0000
To: keshlam@us.ibm.com, www-dom@w3.org
Message-ID: <F87ekzabtneqdGSyMp60000733c@hotmail.com>
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 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:13:48 GMT