The Visitor Pattern and Multiple Dispatch
The Visitor pattern is another classic object-oriented design pattern, one of the 23 patterns introduced in the book Design Patterns – Elements of Reusable Object-Oriented Software, by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides. It was one of the more popular patterns during the golden age of object-oriented programming since it can be used to make large class hierarchies more maintainable. In recent years, the use of Visitor in C++ declined, as large complex hierarchies became less common, and the Visitor pattern is a fairly complex pattern to implement. Generic programming - in particular, the language features added in C++11 and C++14 - makes it easier to implement and maintain the Visitor classes, while the new applications of the old pattern have served to rekindle some of the fading interest in it.
The following topics will be covered in this chapter:
- The Visitor pattern
- Implementations of Visitor...