Skip to content

Commit e2a9d3e

Browse files
committed
Add README.
1 parent c5b867d commit e2a9d3e

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Singleton Pattern
2+
Singleton is a creational design pattern that lets you ensure that a class has only one instance,
3+
while providing a global access point to this instance.
4+
5+
Tutorial: [here](https://refactoring.guru/design-patterns/singleton).
6+
7+
### Diagram:
8+
![Singleton Pattern Diagram](https://user-images.githubusercontent.com/8049534/182938119-78a21534-5751-4dea-afa3-8acaec46eed9.png)
9+
10+
### Client code:
11+
```dart
12+
void main() {
13+
// dart style
14+
Singleton().doSome();
15+
Singleton().doSome();
16+
17+
// standard style
18+
Singleton.instance.doSome();
19+
}
20+
```
21+
22+
### Output:
23+
```
24+
Create singleton once.
25+
doSome()
26+
doSome()
27+
doSome()
28+
```

0 commit comments

Comments
 (0)