Design Patterns - Visitor
Represent an operation to be performed on the elements of an object structure. Elements pass themselves to the Operation object, and this later one performs the operation.
For example, an object structure has elements with price/size, and you want to retrieve full cost or size of all elements. You could define the operation on each single element, and compose them, but you could also create a SumAll class that goes visiting all elements and adding the total cost.
If you are going to be constantly adding new Classes, these methods will be hard to maintain. On the other hand, if the collection of objects is difficult that is modified but you want to keep adding operations, it’s easier to create Visitor classes than to implement the new method on every class when creating a new operation.
Notes References
20210408132546 Computer Science - Design patterns