From: aero6dof@... (Alan Chen) Date: 2004-05-29T02:58:41+09:00 Subject: Re: Visitor Pattern in Ruby Charles Comstock wrote in message news:... > On Thu, 27 May 2004, Robert Klemme wrote: > > > > Visitor has its merits but nevertheless I don't like it very much. On one > > hand you retrofit functionality to a class hierarchy but on the other hand > > you need this class hierarchy's collaboration to make it happen if you use > > visitor. I find this a bit too intertwined. I prefer the "hash lookup with > > class" approach. If you do that inside the visitor, you don't need the > > visitee to call any visit_ methods and your visitor code is > > completely independend from the class hierarchy you want to visit. It seems > > to me to be a better separation of concerns. > > It was designed as far as I can tell for use with compilers, that is where it > mostly frequently appears. In that case I think it does a very good job as you > have a number of passes you need to perform across your AST which hopefully is > well structured into a nice class hiearchy. That way you can generate code for > a AddOp, a BinaryComputeIsh, or some such hiearchy like that, catching what you > need where. An AST is something that is well suited to a very deep class > hiearchy and so the Visitor excels at processing it. As for other applications, > I'm not sure if it's as effective there. Another place I've seen it used effectively is scene graph traversal. The OpenSceneGraph project (http://www.openscenegraph.org) has a nice C++ implementation for their purposes.