You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: antipattern/singleton/README.md
+9-3
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,9 @@
2
2
3
3
## Description
4
4
5
-
The Singleton pattern aims to provide same instance of an objefct and guarantee that there are no duplicates. At the first call the instance is created. Following calls return first instance.
5
+
The Singleton pattern aims to provide same instance of an object and guarantee
6
+
that there are no duplicates. At the first call the instance is created.
7
+
Following calls return first instance.
6
8
7
9
```go
8
10
firstInstance:=GetInstance()
@@ -13,7 +15,7 @@ if firstInstance != secondInstance {
13
15
}
14
16
```
15
17
16
-
Any following calls, update first intance.
18
+
Any following calls, update first instance.
17
19
18
20
```go
19
21
thirdInstance:=GetInstance()
@@ -24,4 +26,8 @@ if thirdInstance.NumberOfCalls() != 3 {
24
26
25
27
## Few words …
26
28
27
-
Is not good pattern if used to bring the state of the applicatoin and can cnange during its lifecycle. Making something global to avoid passing it around is a code smell. But use it to read configuration is good. Used to load a resource just first time is requested and to provide that resource everywere is a good way to use this pattern.
29
+
Is not good pattern if used to bring the state of the application and can
30
+
change during its life cycle. Making something global to avoid passing it
31
+
around is a code smell. But use it to read configuration is good. Used to load
32
+
a resource just first time is requested and to provide that resource every were
0 commit comments