Visitor Design Pattern in iOS and Swift Universe
A classic behavioral design pattern in detail.
Visitor is one of the behavioral design patterns described by the Gang of Four (GoF) in their classic book “Design Patterns: Elements of Reusable Object-Oriented Software”.
The pattern might be useful when there’s a need in performing some similar actions with a group of objects of different type. Or perform an action with an object depending on its specific type, not knowing this type.
In other words, the pattern extends functionality of a set of types by adding similar or having the same source, operations. Furthermore, type structure and implementation stay unaltered.
Of course, the easiest way to explain is through an example.
All provided examples and code snippets are not taken from my working experience, but are composed for academic purposes. I.e., this article is trying to familiarize you with one of the object-oriented techniques and not to discuss specialized problems to solve.
All code here is structured for a better understanding and may have various and even obvious flaws.