The visitor design pattern

2,177 views

Published on

Published in: Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,177
On SlideShare
0
From Embeds
0
Number of Embeds
12
Actions
Shares
0
Downloads
65
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

The visitor design pattern

  1. 1. The Visitor Design Pattern<br />SamnangChhun<br />Yoolk Inc.<br />
  2. 2. Represent an operation to be performed on the elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates.<br />What this?<br />Open Closed Principle is the key<br />The Visitor Design Pattern<br />
  3. 3. Structure<br />
  4. 4. Example<br />
  5. 5. Consequences<br />Benefits<br />Adding new operations is easy<br />Related behavior isn’t spread over the classes defining the object structure; it’s localized in a visitor. Unrelated sets of behavior are partitioned in own visitor subclasses.<br />Liabilities<br />Adding new ConcreteElement class is hard. Each new ConcreteElement give rise to a new abstract operation on Visitor and a corresponding implementation in every ConcreteVisitor class.<br />The ConcreteElement interface must be powerful enough to let visitors do their job. You may be forced to provide public operations that access an element’s internal state, which may compromise its encapsulation.<br />
  6. 6. Don’t forget to review all of them again and again<br />
  7. 7. Thank you!<br />

×