Re: When and where to use Visitor Pattern?



Sam Hwang wrote:

> Why make it so complicated?

Decoupling. There are simply situations where you don't want to touch the
original class when you need to change a specific operation, or where you
even want to allow the definition of additional operations without having to
touch them.

In your example, what if I wanted to display the expression in a Swing UI?
In a Web UI? SWT? We'd probably don't want to have the Expression class know
about all those - that would violate the Single Responsibility Principle.
Visitor is a good match in that situation.

See http://www.butunclebob.com/ArticleS.UncleBob.IuseVisitor

Hope this helps, Ilja


.


Quantcast