Skip to content

Commit b5c6a89

Browse files
committed
Update README.md
1 parent 74360a7 commit b5c6a89

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

multiton/README.md

+28-15
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,34 @@ tags:
99
---
1010

1111
## Also known as
12+
1213
Registry
1314

1415
## Intent
16+
1517
Ensure a class only has limited number of instances and provide a global point of access to them.
1618

1719
## Explanation
1820

1921
Real world example
2022

21-
> The Nazgûl, also called ringwraiths or the Nine Riders, are Sauron's most terrible servants. By definition there's always nine of them.
23+
> The Nazgûl, also called ringwraiths or the Nine Riders, are Sauron's most terrible servants. By
24+
> definition there's always nine of them.
2225
2326
In plain words
2427

2528
> Multiton pattern ensures there's predefined amount of instances available globally.
2629
2730
Wikipedia says
2831

29-
> In software engineering, the multiton pattern is a design pattern which generalizes the singleton pattern. Whereas the singleton allows only one instance of a class to be created, the multiton pattern allows for the controlled creation of multiple instances, which it manages through the use of a map.
32+
> In software engineering, the multiton pattern is a design pattern which generalizes the singleton
33+
> pattern. Whereas the singleton allows only one instance of a class to be created, the multiton
34+
> pattern allows for the controlled creation of multiple instances, which it manages through the use
35+
> of a map.
3036
3137
**Programmatic Example**
3238

33-
Nazgul is the multiton class.
39+
`Nazgul` is the multiton class.
3440

3541
```java
3642
public enum NazgulName {
@@ -71,7 +77,7 @@ public final class Nazgul {
7177
}
7278
```
7379

74-
And here's how we access the Nazgul instances.
80+
And here's how we access the `Nazgul` instances.
7581

7682
```java
7783
LOGGER.info("KHAMUL={}", Nazgul.getInstance(NazgulName.KHAMUL));
@@ -83,22 +89,29 @@ And here's how we access the Nazgul instances.
8389
LOGGER.info("ADUNAPHEL={}", Nazgul.getInstance(NazgulName.ADUNAPHEL));
8490
LOGGER.info("REN={}", Nazgul.getInstance(NazgulName.REN));
8591
LOGGER.info("UVATHA={}", Nazgul.getInstance(NazgulName.UVATHA));
86-
87-
// KHAMUL=com.iluwatar.multiton.Nazgul@2b214b94
88-
// MURAZOR=com.iluwatar.multiton.Nazgul@17814b1c
89-
// DWAR=com.iluwatar.multiton.Nazgul@7ac9af2a
90-
// JI_INDUR=com.iluwatar.multiton.Nazgul@7bb004b8
91-
// AKHORAHIL=com.iluwatar.multiton.Nazgul@78e89bfe
92-
// HOARMURATH=com.iluwatar.multiton.Nazgul@652ce654
93-
// ADUNAPHEL=com.iluwatar.multiton.Nazgul@522ba524
94-
// REN=com.iluwatar.multiton.Nazgul@29c5ee1d
95-
// UVATHA=com.iluwatar.multiton.Nazgul@15cea7b0
92+
```
93+
94+
Program output:
95+
96+
```
97+
KHAMUL=com.iluwatar.multiton.Nazgul@2b214b94
98+
MURAZOR=com.iluwatar.multiton.Nazgul@17814b1c
99+
DWAR=com.iluwatar.multiton.Nazgul@7ac9af2a
100+
JI_INDUR=com.iluwatar.multiton.Nazgul@7bb004b8
101+
AKHORAHIL=com.iluwatar.multiton.Nazgul@78e89bfe
102+
HOARMURATH=com.iluwatar.multiton.Nazgul@652ce654
103+
ADUNAPHEL=com.iluwatar.multiton.Nazgul@522ba524
104+
REN=com.iluwatar.multiton.Nazgul@29c5ee1d
105+
UVATHA=com.iluwatar.multiton.Nazgul@15cea7b0
96106
```
97107

98108
## Class diagram
109+
99110
![alt text](./etc/multiton.png "Multiton")
100111

101112
## Applicability
113+
102114
Use the Multiton pattern when
103115

104-
* there must be specific number of instances of a class, and they must be accessible to clients from a well-known access point
116+
* There must be specific number of instances of a class, and they must be accessible to clients from
117+
a well-known access point.

0 commit comments

Comments
 (0)