Skip to content

Commit 0758ca6

Browse files
committed
Update README.md
1 parent 15e7002 commit 0758ca6

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,10 @@
227227

228228
##Visitor
229229
**Intent:** 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.
230+
231+
![alt text](https://github.com/iluwatar/java-design-patterns/blob/master/visitor/etc/visitor.jpg "Visitor")
232+
233+
**Applicability:** Use the Visitor pattern when
234+
* an object structure contains many classes of objects with differing interfaces, and you want to perform operations on these objects that depend on their concrete classes
235+
* many distinct and unrelated operations need to be performed on objects in an object structure, and you want to avoid "polluting" their classes with these operations. Visitor lets you keep related operations together by defining them in one class. When the object structure is shared by many applications, use Visitor to put operations in just those applications that need them
236+
* the classes defining the object structure rarely change, but you often want to define new operations over the structure. Changing the object structure classes requires redefining the interface to all visitors, which is potentially costly. If the object structure classes change often, then it's probably better to define the operations in those classes

0 commit comments

Comments
 (0)