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: John Cowan <jcowan@reutershealth.com>
Date: Tue, 20 Mar 2001 16:21:15 -0500
Message-ID: <3AB7C9CB.3050009@reutershealth.com>
To: Peter Meyer <petermeyer99@hotmail.com>
CC: www-dom@w3.org
Peter Meyer wrote:


> I agree that you can implement the same functionality using a switch 
> statement and using a visitor pattern. What I personally dislike about 
> the switch statement is that I have to rely on information stored in a 
> field to switch, instead of type information of the classes I am 
> traversing.
>
> If I never create my own classes for nodes (i.e. I rely on the basic DOM 
> classes), this works well, but the approach tends to be fragile if I 
> need to have application dependent node subclasses based for example on 
> element types.

Granted.  But by the same token, if the implementation uses *fewer* classes
than it has interfaces, then the Visitor pattern becomes implementation-specific.
In the HTML DOM, for example, the 50+ element interfaces can be represented
(IIRC) by about 6 classes.  Visitor wouldn't help much; you need to 
have a switch operating over the element name.  Other DOMs may very
well use fewer classes than interfaces even in the core.


-- 
There is / one art             || John Cowan <jcowan@reutershealth.com>
no more / no less              || http://www.reutershealth.com
to do / all things             || http://www.ccil.org/~cowan
with art- / lessness           \\ -- Piet Hein
Received on Tuesday, 20 March 2001 16:19:41 GMT

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