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: Writerside/topics/Visitor.md
+36-9Lines changed: 36 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -62,17 +62,44 @@ classDiagram
62
62
63
63
Trong sơ đồ này, `DocumentElement` là một interface đại diện cho các loại phần tử của tài liệu mà có thể được "thăm" bởi các visitor. `Text`, `Table`, và `Image` là các lớp cụ thể biểu diễn các loại phần tử khác
64
64
65
-
## Cấu trúc
65
+
## Cấu trúc của Visitor Pattern
66
66
67
-
Các thành phần chính trong Visitor Pattern:
68
-
69
-
- Visitor: định nghĩa các phương thức thao tác trên các Element.
70
-
71
-
- ConcreteVisitor: triển khai các phương thức trên.
72
-
73
-
- Element: định nghĩa phương thức accept nhận vào một Visitor.
67
+
```mermaid
68
+
classDiagram
69
+
class Visitor {
70
+
+visitConcreteElementA(ConcreteElementA)
71
+
+visitConcreteElementB(ConcreteElementB)
72
+
}
73
+
class ConcreteVisitor1 {
74
+
+visitConcreteElementA(ConcreteElementA)
75
+
+visitConcreteElementB(ConcreteElementB)
76
+
}
77
+
class ConcreteVisitor2 {
78
+
+visitConcreteElementA(ConcreteElementA)
79
+
+visitConcreteElementB(ConcreteElementB)
80
+
}
81
+
class Element {
82
+
+accept(Visitor)
83
+
}
84
+
class ConcreteElementA {
85
+
+accept(Visitor)
86
+
}
87
+
class ConcreteElementB {
88
+
+accept(Visitor)
89
+
}
90
+
91
+
Visitor <|.. ConcreteVisitor1 : Extends
92
+
Visitor <|.. ConcreteVisitor2 : Extends
93
+
Element <|.. ConcreteElementA : Extends
94
+
Element <|.. ConcreteElementB : Extends
95
+
ConcreteElementA ..> Visitor : Uses
96
+
ConcreteElementB ..> Visitor : Uses
97
+
```
74
98
75
-
- ConcreteElement: các lớp cụ thể cần áp dụng thao tác.
99
+
-`Visitor` là một interface hoặc abstract class chứa một loạt các phương thức visit(), mỗi phương thức cho một loại element khác nhau.
100
+
-`ConcreteVisitor1` và `ConcreteVisitor2` là các lớp cụ thể triển khai interface `Visitor`, cung cấp cách thực hiện cụ thể cho mỗi phương thức visit().
101
+
-`Element` là một interface hoặc abstract class chứa phương thức accept(), trong đó tham số là một đối tượng Visitor.
102
+
-`ConcreteElementA` và `ConcreteElementB` là các lớp cụ thể triển khai `Element`, mỗi lớp cung cấp triển khai cụ thể cho phương thức accept(), thường là gọi phương thức visit() của Visitor và truyền chính nó như một đối số.
0 commit comments