Skip to content

Commit 3d7b2b3

Browse files
Create Software Design Pattern.md
1 parent b801163 commit 3d7b2b3

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

Software Design Pattern.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
next chain
33+
}
34+
35+
func (c check2) check(p person) {
36+
fmt.Println("check2")
37+
}
38+
39+
func (c check2) setNext(ch chain) {
40+
c.next = ch
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

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy