Thursday, September 12, 2013

Visitor Design Pattern Example

Visitor Design Pattern: The visitor design pattern is a way of separating an some logic from an object structure on which it operates. Basically it allows you to add new operations on existing classes without modifying them, So visitor design pattern is a great way to provide a flexible design.

Note:  Visitor pattern has some flaws.
If we add a new class, the visitor class needs a new method. Furthermore, it is indeed likely that a new visiting method will need the definition of a new visitor patter, as well as a new accept method in every class of the hierarchy, visitor uses dual dispatching.

When to use: when you have a complex structure, i.e, a hierarchy, tree structure or something else that's not simply linear, you can apply the visitor to simplify the complex structure.

Lets understand it by one hierarchy problem example ...


No comments :

Post a Comment