Re: latest DOM spec 19980720

Michael Allen <Michael.R.Allen@Eng.Sun.COM> writes:

> 	With all this talk of quickly casting to subclasses from a base
> class reference, I wonder if anyone has ever thought of putting Visitor
> design pattern functionality into Node?  I have also heard the Visitor
> pattern referred to as "double dispatch". 

  [excellent discussion of the pattern snipped.  See also p. 331 in the Gang
   of Four book]

<hit target=forehead implement=hand>of course!</hit>

It still has the problem of having to be extended whenever you add a
subclass to Node, but at least it's better than adding conversion methods to
Node.  Something like the HTMLNodeVisitor could get pretty ugly.

> 	To avoid type checking what kind of NodeVisitor a Node has received,
> you might make NodeVisitor an abstract base class with an Enumerated type
> field which contains an int (or bitfield, maybe) which specifies its type.
> That way, subclasses which the base NodeVisitor doesn't cover could check
> the type of visitors without doing an instanceof test.

I think it would be better to extend NodeVisitor at the same time as you
specialize Node (which, by the way, I notice that the HTML application
doesn't do -- that's a problem):

interface HTMLNode: Node {
  readonly attribute HTMLNode parentHTMLNode;
  ...

  void visit(in HTMLVisitor v)
}
	
> 	Throwing my hat in the ring,

Nice hat.

-- 
 Stephen R. Savitzky   Chief Software Scientist, Ricoh Silicon Valley, Inc., 
<steve@rsv.ricoh.com>                            California Research Center
 voice: 650.496.5710   fax: 650.854.8740    URL: http://rsv.ricoh.com/~steve/
  home: <steve@starport.com> URL: http://www.starport.com/people/steve/

Received on Tuesday, 21 July 1998 20:43:01 UTC