Tag Archives: visitor-pattern

Design Patterns: Visitor

The visitor design pattern can be used when you need to perform an action on the object but the logic isn’t semantically correct to be placed in that object. So we can have an external object “visit” that instance and call an action to be performed.

In games we could use this pattern on attacks. In the game Breath of Fire IV, for example, there are many different types of attacks and different types of creatures. One might recover life instead of taking damage depending on the type of attack. The logic to determine what happens after an attack happen can be isolated on a visitor.
Continue reading