We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b801163 commit 3d7b2b3Copy full SHA for 3d7b2b3
Software Design Pattern.md
@@ -0,0 +1,51 @@
1
+# 设计模式
2
+
3
+1. 责任链模式
4
5
+```go
6
+package main
7
8
+import "fmt"
9
10
+type person struct {
11
+}
12
13
+type chain interface {
14
+ check(person)
15
+ setNext(chain)
16
17
18
+type check1 struct {
19
+ next chain
20
21
22
+func (c check1) check(p person) {
23
+ fmt.Println("check1")
24
+ c.next.check(p)
25
26
27
+func (c check1) setNext(ch chain) {
28
+ c.next = ch
29
30
31
+type check2 struct {
32
33
34
35
+func (c check2) check(p person) {
36
+ fmt.Println("check2")
37
38
39
+func (c check2) setNext(ch chain) {
40
41
42
43
+func main() {
44
+ p := person{}
45
46
+ c1 := &check1{next: check2{}}
47
+ c1.check(p)
48
49
50
+```
51
0 commit comments