1
0
mirror of https://github.com/tmrts/go-patterns.git synced 2024-11-25 06:26:06 +03:00

creational/singleton: use fmt.Println to show the result

This commit is contained in:
Tamer Tas 2016-09-06 19:26:44 +03:00
parent 066d2f6b42
commit 077bcecea0

View File

@ -1,7 +1,9 @@
# Singleton Pattern # Singleton Pattern
Singleton creational design pattern restricts the instantiation of a type to a single object. Singleton creational design pattern restricts the instantiation of a type to a single object.
## Implementation ## Implementation
```go ```go
package singleton package singleton
@ -21,6 +23,7 @@ func New() *singleton {
``` ```
## Usage ## Usage
```go ```go
s := singleton.New() s := singleton.New()
@ -28,8 +31,10 @@ s["this"] = "that"
s2 := singleton.New() s2 := singleton.New()
// s2["this"] == "that" fmt.Println("This is ", s2["this"])
// This is that
``` ```
## Rules of Thumb ## Rules of Thumb
- Singleton pattern represents a global state and most of the time reduces testability. - Singleton pattern represents a global state and most of the time reduces testability.