Added code comments for Multiton.
This commit is contained in:
		@@ -1,5 +1,17 @@
 | 
				
			|||||||
package com.iluwatar;
 | 
					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 class App {
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
    public static void main( String[] args ) {
 | 
					    public static void main( String[] args ) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,6 +3,12 @@ package com.iluwatar;
 | 
				
			|||||||
import java.util.Map;
 | 
					import java.util.Map;
 | 
				
			||||||
import java.util.concurrent.ConcurrentHashMap;
 | 
					import java.util.concurrent.ConcurrentHashMap;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 | 
					 * Nazgul is a Multiton class. Nazgul instances can be queried
 | 
				
			||||||
 | 
					 * using getInstance() method.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
public class Nazgul {
 | 
					public class Nazgul {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private static Map<NazgulName, Nazgul> nazguls;
 | 
						private static Map<NazgulName, Nazgul> nazguls;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,10 @@
 | 
				
			|||||||
package com.iluwatar;
 | 
					package com.iluwatar;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 | 
					 * Each Nazgul has different NazgulName.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
public enum NazgulName {
 | 
					public enum NazgulName {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	KHAMUL, MURAZOR, DWAR, JI_INDUR, AKHORAHIL, HOARMURATH, ADUNAPHEL, REN, UVATHA;
 | 
						KHAMUL, MURAZOR, DWAR, JI_INDUR, AKHORAHIL, HOARMURATH, ADUNAPHEL, REN, UVATHA;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user