I read a book about the visitor pattern. It gives the same class diagram as in the oodesign\'s website.
It says that adding new ConcreteElement classes is hard. But I di
If you add a new concrete element, then all of your visitor classes will need to add a new visit
method for the new element. If you didn't use visitors, you would have to add the equivalent methods to your new concrete element anyway.
But adding a new method to each your visitors may be harder than adding the equivalent set of methods to a new element class. The reason is that visitors often need to traverse the element tree structure and may need to manage its own state data as it does so. Adding a new visit
method may require modifying that state data which involves thinking about how the new method interacts with existing visit
methods for other elements.
It may be simpler to add the equivalent methods to your new element class if you didn't have visitors because you will only need to worry about the internal state of the new concrete element which is more cohesive.