Search code examples
design-patternsvisitor-pattern

Visitor pattern: change object state?


Is it acceptable that visitor change the state of object in which it operates? These kind of operation are not considered as anti patterns?


Solution

  • It's completely fine to modify the objects that are visited.

    Just make sure that your visitor class is named appropriately, so it is obvious that it has a side-effect.