Skip to content

Commit c204b24

Browse files
committed
Update README.md
1 parent 2e98dcf commit c204b24

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

singleton/README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,26 @@ tags:
99
---
1010

1111
## Intent
12-
Ensure a class only has one instance, and provide a global point of
13-
access to it.
12+
13+
Ensure a class only has one instance, and provide a global point of access to it.
1414

1515

1616
## Explanation
17+
1718
Real world example
1819

19-
> There can only be one ivory tower where the wizards study their magic. The same enchanted ivory tower is always used by the wizards. Ivory tower here is singleton.
20+
> There can only be one ivory tower where the wizards study their magic. The same enchanted ivory
21+
> tower is always used by the wizards. Ivory tower here is singleton.
2022
2123
In plain words
2224

2325
> Ensures that only one object of a particular class is ever created.
2426
2527
Wikipedia says
2628

27-
> In software engineering, the singleton pattern is a software design pattern that restricts the instantiation of a class to one object. This is useful when exactly one object is needed to coordinate actions across the system.
29+
> In software engineering, the singleton pattern is a software design pattern that restricts the
30+
> instantiation of a class to one object. This is useful when exactly one object is needed to
31+
> coordinate actions across the system.
2832
2933
**Programmatic Example**
3034

@@ -38,7 +42,7 @@ public enum EnumIvoryTower {
3842
}
3943
```
4044

41-
Then in order to use
45+
Then in order to use:
4246

4347
```java
4448
var enumIvoryTower1 = EnumIvoryTower.INSTANCE;
@@ -47,9 +51,11 @@ assertEquals(enumIvoryTower1, enumIvoryTower2); // true
4751
```
4852

4953
## Class diagram
54+
5055
![alt text](./etc/singleton.urm.png "Singleton pattern class diagram")
5156

5257
## Applicability
58+
5359
Use the Singleton pattern when
5460

5561
* There must be exactly one instance of a class, and it must be accessible to clients from a well-known access point

0 commit comments

Comments
 (0)