Design patterns implementation examples

Visitor

Definition:

Adds new operations to existing object structure without modifying that structure. Separates an algorithm from an object structure on which it operates.


Example:

An example would be a guest visiting a household. A guest talks to each family member, but he talks to each one in a different way – he will not talk the same with adults as he will with children. The guest has indispensable knowledge of how to talk to certain household member. This knowledge however does not have an impact on the household.


C++ code:

/src/visitor.cpp
Download source code

Visitor UML class diagram:
Visitor UML class diagram

Visitor UML sequence diagram:
Visitor UML sequence diagram