Update README.md
This commit is contained in:
		@@ -9,16 +9,19 @@ tags:
 | 
				
			|||||||
---
 | 
					---
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Also known as
 | 
					## Also known as
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Registry
 | 
					Registry
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Intent
 | 
					## Intent
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Ensure a class only has limited number of instances and provide a global point of access to them.
 | 
					Ensure a class only has limited number of instances and provide a global point of access to them.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Explanation
 | 
					## Explanation
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Real world example
 | 
					Real world example
 | 
				
			||||||
 | 
					
 | 
				
			||||||
> The Nazgûl, also called ringwraiths or the Nine Riders, are Sauron's most terrible servants. By definition there's always nine of them.           
 | 
					> The Nazgûl, also called ringwraiths or the Nine Riders, are Sauron's most terrible servants. By 
 | 
				
			||||||
 | 
					> definition there's always nine of them.           
 | 
				
			||||||
 | 
					
 | 
				
			||||||
In plain words
 | 
					In plain words
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -26,11 +29,14 @@ In plain words
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
Wikipedia says
 | 
					Wikipedia says
 | 
				
			||||||
 | 
					
 | 
				
			||||||
> 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.
 | 
					> 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.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
**Programmatic Example**
 | 
					**Programmatic Example**
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Nazgul is the multiton class.
 | 
					`Nazgul` is the multiton class.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```java
 | 
					```java
 | 
				
			||||||
public enum NazgulName {
 | 
					public enum NazgulName {
 | 
				
			||||||
@@ -71,7 +77,7 @@ public final class Nazgul {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
And here's how we access the Nazgul instances.
 | 
					And here's how we access the `Nazgul` instances.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```java
 | 
					```java
 | 
				
			||||||
    LOGGER.info("KHAMUL={}", Nazgul.getInstance(NazgulName.KHAMUL));
 | 
					    LOGGER.info("KHAMUL={}", Nazgul.getInstance(NazgulName.KHAMUL));
 | 
				
			||||||
@@ -83,22 +89,29 @@ And here's how we access the Nazgul instances.
 | 
				
			|||||||
    LOGGER.info("ADUNAPHEL={}", Nazgul.getInstance(NazgulName.ADUNAPHEL));
 | 
					    LOGGER.info("ADUNAPHEL={}", Nazgul.getInstance(NazgulName.ADUNAPHEL));
 | 
				
			||||||
    LOGGER.info("REN={}", Nazgul.getInstance(NazgulName.REN));
 | 
					    LOGGER.info("REN={}", Nazgul.getInstance(NazgulName.REN));
 | 
				
			||||||
    LOGGER.info("UVATHA={}", Nazgul.getInstance(NazgulName.UVATHA));
 | 
					    LOGGER.info("UVATHA={}", Nazgul.getInstance(NazgulName.UVATHA));
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // KHAMUL=com.iluwatar.multiton.Nazgul@2b214b94
 | 
					Program output:
 | 
				
			||||||
    // MURAZOR=com.iluwatar.multiton.Nazgul@17814b1c
 | 
					
 | 
				
			||||||
    // DWAR=com.iluwatar.multiton.Nazgul@7ac9af2a
 | 
					```
 | 
				
			||||||
    // JI_INDUR=com.iluwatar.multiton.Nazgul@7bb004b8
 | 
					KHAMUL=com.iluwatar.multiton.Nazgul@2b214b94
 | 
				
			||||||
    // AKHORAHIL=com.iluwatar.multiton.Nazgul@78e89bfe
 | 
					MURAZOR=com.iluwatar.multiton.Nazgul@17814b1c
 | 
				
			||||||
    // HOARMURATH=com.iluwatar.multiton.Nazgul@652ce654
 | 
					DWAR=com.iluwatar.multiton.Nazgul@7ac9af2a
 | 
				
			||||||
    // ADUNAPHEL=com.iluwatar.multiton.Nazgul@522ba524
 | 
					JI_INDUR=com.iluwatar.multiton.Nazgul@7bb004b8
 | 
				
			||||||
    // REN=com.iluwatar.multiton.Nazgul@29c5ee1d
 | 
					AKHORAHIL=com.iluwatar.multiton.Nazgul@78e89bfe
 | 
				
			||||||
    // UVATHA=com.iluwatar.multiton.Nazgul@15cea7b0
 | 
					HOARMURATH=com.iluwatar.multiton.Nazgul@652ce654
 | 
				
			||||||
 | 
					ADUNAPHEL=com.iluwatar.multiton.Nazgul@522ba524
 | 
				
			||||||
 | 
					REN=com.iluwatar.multiton.Nazgul@29c5ee1d
 | 
				
			||||||
 | 
					UVATHA=com.iluwatar.multiton.Nazgul@15cea7b0
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Class diagram
 | 
					## Class diagram
 | 
				
			||||||
 | 
					
 | 
				
			||||||

 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Applicability
 | 
					## Applicability
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Use the Multiton pattern when
 | 
					Use the Multiton pattern when
 | 
				
			||||||
 | 
					
 | 
				
			||||||
* there must be specific number of instances of a class, and they must be accessible to clients from a well-known access point
 | 
					* There must be specific number of instances of a class, and they must be accessible to clients from 
 | 
				
			||||||
 | 
					a well-known access point.
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user