We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 066d2f6 commit 077bcecCopy full SHA for 077bcec
creational/singleton.md
@@ -1,7 +1,9 @@
1
-#Singleton Pattern
+# Singleton Pattern
2
+
3
Singleton creational design pattern restricts the instantiation of a type to a single object.
4
5
## Implementation
6
7
```go
8
package singleton
9
@@ -21,15 +23,18 @@ func New() *singleton {
21
23
```
22
24
25
## Usage
26
27
28
s := singleton.New()
29
30
s["this"] = "that"
31
32
s2 := singleton.New()
33
-// s2["this"] == "that"
34
+fmt.Println("This is ", s2["this"])
35
+// This is that
36
37
38
## Rules of Thumb
39
40
- Singleton pattern represents a global state and most of the time reduces testability.
0 commit comments