the visitor design pattern

7

Click here to load reader

Upload: samnang-chhun

Post on 06-May-2015

1.380 views

Category:

Education


1 download

TRANSCRIPT

Page 1: The visitor design pattern

The Visitor Design Pattern

Samnang ChhunYoolk Inc.

Page 2: The visitor design pattern

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.What th

is?

Open Closed Principle is the key

The Visitor Design Pattern

Page 3: The visitor design pattern

Structure

Page 4: The visitor design pattern

Example

Page 5: The visitor design pattern

Consequences• Benefits

– Adding new operations is easy– 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.

• Liabilities– 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.

– 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.

Page 6: The visitor design pattern

Don’t forget to review all of them again and again

Page 7: The visitor design pattern

Thank you!