solution to issue #602. Implemented multiton with enum, added example to app.java, a test for the enum, and commented my code
This commit is contained in:
parent
960d2ea6f7
commit
ac57d67f45
@ -31,9 +31,12 @@ import org.slf4j.LoggerFactory;
|
||||
* pattern defines many globally accessible objects. The client asks for the correct instance from
|
||||
* the Multiton by passing an enumeration as parameter.
|
||||
* <p>
|
||||
* In this example {@link Nazgul} is the Multiton and we can ask single {@link Nazgul} from it using
|
||||
* {@link NazgulName}. The {@link Nazgul}s are statically initialized and stored in concurrent hash
|
||||
* map.
|
||||
* There is more than one way to implement the multiton design pattern. In the first example
|
||||
* {@link Nazgul} is the Multiton and we can ask single {@link Nazgul} from it using {@link NazgulName}.
|
||||
* The {@link Nazgul}s are statically initialized and stored in concurrent hash map.
|
||||
* <p>
|
||||
* In the enum implementation {@link NazgulEnum} is the multiton. It is static and mutable because
|
||||
* of the way java supports enums.
|
||||
*
|
||||
*/
|
||||
public class App {
|
||||
@ -46,6 +49,7 @@ public class App {
|
||||
* @param args command line args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
// eagerly initialized multiton
|
||||
LOGGER.info("KHAMUL={}", Nazgul.getInstance(NazgulName.KHAMUL));
|
||||
LOGGER.info("MURAZOR={}", Nazgul.getInstance(NazgulName.MURAZOR));
|
||||
LOGGER.info("DWAR={}", Nazgul.getInstance(NazgulName.DWAR));
|
||||
@ -55,5 +59,16 @@ public class App {
|
||||
LOGGER.info("ADUNAPHEL={}", Nazgul.getInstance(NazgulName.ADUNAPHEL));
|
||||
LOGGER.info("REN={}", Nazgul.getInstance(NazgulName.REN));
|
||||
LOGGER.info("UVATHA={}", Nazgul.getInstance(NazgulName.UVATHA));
|
||||
|
||||
// enum multiton
|
||||
LOGGER.info("KHAMUL={}", NazgulEnum.KHAMUL);
|
||||
LOGGER.info("MURAZOR={}", NazgulEnum.MURAZOR);
|
||||
LOGGER.info("DWAR={}", NazgulEnum.DWAR);
|
||||
LOGGER.info("JI_INDUR={}", NazgulEnum.JI_INDUR);
|
||||
LOGGER.info("AKHORAHIL={}", NazgulEnum.AKHORAHIL);
|
||||
LOGGER.info("HOARMURATH={}", NazgulEnum.HOARMURATH);
|
||||
LOGGER.info("ADUNAPHEL={}", NazgulEnum.ADUNAPHEL);
|
||||
LOGGER.info("REN={}", NazgulEnum.REN);
|
||||
LOGGER.info("UVATHA={}", NazgulEnum.UVATHA);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user