Visitor Pattern

Visitor design pattern is one of the behavioral design patterns. It is used when we have to perform an operation on a group of similar kind of Objects. With the help of visitor pattern, we can move the operational logic from the objects to another class.

The visitor pattern consists of two parts:

  • a method called Visit() which is implemented by the visitor and is called for every element in the data structure
  • visitable classes providing Accept() methods that accept a visitor

visitor-patttern-uml.png