title: Combining Enum Classes with Strategy Pattern for Modular Design
body: <p>I am a biologist who is trying to improve my dated knowledge of Java and OOP. I am going through the exercise of writing a game to practice good software design and modularity (why make something fun?).</p>
  
  <p>The idea is like Risk but with international banking. Each bank deals with different currencies; each currency uses different denominations. The banks all offer the same functions (balance, withdraw, deposit, exchange) and so would do well with an interface. A currency can also be well described using an Enum representing each denomination and its value.</p>
  
  <p>This is my very simple example. I can create new Country() objects for each county in the game.</p>
  
  <p><strong>1) Am I forced to manually specify every single country with its respective currency?</strong> E.g.:</p>
  
  <pre><code>Country Canada = new Country(CANCurrency);
  </code></pre>
  
  <p>This seems rather clunky and there must be a better way to do this.</p>
  
  <p><strong>2) From a class using County(), how can I directly access its (indirectly contained) Enum values?</strong></p>
  
  <p>Each country looks like this:</p>
  
  <pre><code>public class Country {
  
      private final String name;
      private ICurrency currency;
  
      public Country(String name, ICurrency currency) {
          this.name = name;
          this.currency = currency;
      }
  
      // How do I access the specific Enum constants here?
  
  }
  </code></pre>
  
  <p>This is my Banking interface:</p>
  
  <pre><code>public interface IBank {
      // Standard banking methods.
      public void deposit(int amount);
      public void withdraw(int amount);
      public int balance();
      public int exchange (Currency demandType, int demand, Currency offerType, int offer);
  }
  </code></pre>
  
  <p>Each country's Currency will largely have similar code, except for the denominations.</p>
  
  <pre><code>public interface ICurrency {
      public Currency getCurrency();
      // Maybe some more helper methods here.
  }
  </code></pre>
  
  <p>This is the Currency for Canada:</p>
  
  <pre><code>public enum CANCurrency interface ICurrency {
      LOONIE(1), TWONIE(2), FIVE(5); // etc....
  }
  </code></pre>
  
  <p>and the currency for USA:</p>
  
  <pre><code>public enum USACurrency interface ICurrency {
      ONE(1), FIVE(5), TEN(10); // etc....
  }
  </code></pre>