Skip to content

Commit f4a1937

Browse files
Update 设计模式.md
1 parent b23d8d7 commit f4a1937

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

设计模式.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# 设计模式
22

3-
1. 责任链模式
3+
4+
5+
## 责任链模式
46

57
```go
68
package main
@@ -49,3 +51,32 @@ func main() {
4951

5052
```
5153

54+
55+
56+
57+
58+
## 单例模式
59+
60+
```go
61+
package main
62+
63+
import "sync"
64+
65+
type people struct {
66+
}
67+
68+
var instance *people
69+
var once sync.Once
70+
71+
func getInstance() *people {
72+
once.Do(func() {
73+
instance = &people{}
74+
})
75+
return instance
76+
}
77+
78+
func main() {
79+
80+
}
81+
```
82+

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