Skip to content

Commit 077bcec

Browse files
committed
creational/singleton: use fmt.Println to show the result
1 parent 066d2f6 commit 077bcec

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

creational/singleton.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
#Singleton Pattern
1+
# Singleton Pattern
2+
23
Singleton creational design pattern restricts the instantiation of a type to a single object.
34

45
## Implementation
6+
57
```go
68
package singleton
79

@@ -21,15 +23,18 @@ func New() *singleton {
2123
```
2224

2325
## Usage
26+
2427
```go
2528
s := singleton.New()
2629

2730
s["this"] = "that"
2831

2932
s2 := singleton.New()
3033

31-
// s2["this"] == "that"
34+
fmt.Println("This is ", s2["this"])
35+
// This is that
3236
```
3337

3438
## Rules of Thumb
39+
3540
- Singleton pattern represents a global state and most of the time reduces testability.

0 commit comments

Comments
 (0)