GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — solution to issue #602. Implemented multiton with enum, added example… · coding0011/java-design-patterns@ac57d67

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • multiton/src/main/java/com/iluwatar/multiton
    • App.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎multiton/src/main/java/com/iluwatar/multiton/App.java‎

Copy file name to clipboardExpand all lines: multiton/src/main/java/com/iluwatar/multiton/App.java
+18-3Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@
3131
* pattern defines many globally accessible objects. The client asks for the correct instance from
3232
* the Multiton by passing an enumeration as parameter.
3333
* <p>
34-
* In this example {@link Nazgul} is the Multiton and we can ask single {@link Nazgul} from it using
35-
* {@link NazgulName}. The {@link Nazgul}s are statically initialized and stored in concurrent hash
36-
* map.
34+
* There is more than one way to implement the multiton design pattern. In the first example
35+
* {@link Nazgul} is the Multiton and we can ask single {@link Nazgul} from it using {@link NazgulName}.
36+
* The {@link Nazgul}s are statically initialized and stored in concurrent hash map.
37+
* <p>
38+
* In the enum implementation {@link NazgulEnum} is the multiton. It is static and mutable because
39+
* of the way java supports enums.
3740
*
3841
*/
3942
public class App {
@@ -46,6 +49,7 @@ public class App {
4649
* @param args command line args
4750
*/
4851
public static void main(String[] args) {
52+
// eagerly initialized multiton
4953
LOGGER.info("KHAMUL={}", Nazgul.getInstance(NazgulName.KHAMUL));
5054
LOGGER.info("MURAZOR={}", Nazgul.getInstance(NazgulName.MURAZOR));
5155
LOGGER.info("DWAR={}", Nazgul.getInstance(NazgulName.DWAR));
@@ -55,5 +59,16 @@ public static void main(String[] args) {
5559
LOGGER.info("ADUNAPHEL={}", Nazgul.getInstance(NazgulName.ADUNAPHEL));
5660
LOGGER.info("REN={}", Nazgul.getInstance(NazgulName.REN));
5761
LOGGER.info("UVATHA={}", Nazgul.getInstance(NazgulName.UVATHA));
62+
63+
// enum multiton
64+
LOGGER.info("KHAMUL={}", NazgulEnum.KHAMUL);
65+
LOGGER.info("MURAZOR={}", NazgulEnum.MURAZOR);
66+
LOGGER.info("DWAR={}", NazgulEnum.DWAR);
67+
LOGGER.info("JI_INDUR={}", NazgulEnum.JI_INDUR);
68+
LOGGER.info("AKHORAHIL={}", NazgulEnum.AKHORAHIL);
69+
LOGGER.info("HOARMURATH={}", NazgulEnum.HOARMURATH);
70+
LOGGER.info("ADUNAPHEL={}", NazgulEnum.ADUNAPHEL);
71+
LOGGER.info("REN={}", NazgulEnum.REN);
72+
LOGGER.info("UVATHA={}", NazgulEnum.UVATHA);
5873
}
5974
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.