You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: acyclic-visitor/README.md
+122-4Lines changed: 122 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,12 +9,126 @@ tags:
9
9
---
10
10
11
11
## Intent
12
-
Allow new functions to be added to existing class hierarchies without affecting those hierarchies, and without creating the troublesome dependency cycles that are inherent to the GOF VISITOR Pattern.
12
+
13
+
Allow new functions to be added to existing class hierarchies without affecting those hierarchies, and without creating
14
+
the troublesome dependency cycles that are inherent to the GoF Visitor Pattern.
15
+
16
+
## Explanation
17
+
18
+
Real world example
19
+
20
+
> We have a hierarchy of modem classes. The modems in this hierarchy need to be visited by an external algorithm based
21
+
> on filtering criteria (is it Unix or DOS compatible modem).
22
+
23
+
In plain words
24
+
25
+
> Acyclic Visitor allows functions to be added to existing class hierarchies without modifying the hierarchies.
* When you need to add a new function to an existing hierarchy without the need to alter or affect that hierarchy.
@@ -24,6 +138,7 @@ This pattern can be used:
24
138
* When the recompilation, relinking, retesting or redistribution of the derivatives of Element is very expensive.
25
139
26
140
## Consequences
141
+
27
142
The good:
28
143
29
144
* No dependency cycles between class hierarchies.
@@ -32,11 +147,14 @@ The good:
32
147
33
148
The bad:
34
149
35
-
* Violates the principle of least surprise or Liskov's Substitution principle by showing that it can accept all visitors but actually only being interested in particular visitors.
150
+
* Violates [Liskov's Substitution Principle](https://java-design-patterns.com/principles/#liskov-substitution-principle) by showing that it can accept all visitors but actually only being interested in particular visitors.
36
151
* Parallel hierarchy of visitors has to be created for all members in visitable class hierarchy.
0 commit comments