Added code comments for Multiton.

This commit is contained in:
Ilkka Seppala 2015-05-16 00:27:06 +03:00
parent f2457699b0
commit d0c32782ce
3 changed files with 23 additions and 0 deletions

View File

@ -1,5 +1,17 @@
package com.iluwatar;
/**
*
* Whereas Singleton design pattern introduces single globally
* accessible object the Multiton pattern defines many globally
* accessible objects. The client asks for the correct instance
* from the Multiton by passing an enumeration as parameter.
*
* In this example Nazgul is the Multiton and we can ask single
* Nazgul from it using NazgulName. The Nazguls are statically
* initialized and stored in concurrent hash map.
*
*/
public class App {
public static void main( String[] args ) {

View File

@ -3,6 +3,12 @@ package com.iluwatar;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
*
* Nazgul is a Multiton class. Nazgul instances can be queried
* using getInstance() method.
*
*/
public class Nazgul {
private static Map<NazgulName, Nazgul> nazguls;

View File

@ -1,5 +1,10 @@
package com.iluwatar;
/**
*
* Each Nazgul has different NazgulName.
*
*/
public enum NazgulName {
KHAMUL, MURAZOR, DWAR, JI_INDUR, AKHORAHIL, HOARMURATH, ADUNAPHEL, REN, UVATHA;