title: trouble making polymorphism defeat those switch/case statements
body: <p>Continuing on previous questions (<a href="https://stackoverflow.com/questions/1215207/refactoring-multiple-if-else-conditionals-in-a-method">here</a>, and <a href="https://stackoverflow.com/questions/1219032/referencing-each-case-of-a-switch-from-a-conditional-inside-a-different-method-in">here</a>), I implemented a basic command pattern, created my command classes and coded to an interface, so when any command is used, to call the <code>execute()</code> method. </p>
  
  <p>However, I am still finding myself unable to shake those case statements: I am reading each character from a master/decision String, which is made up of random, repeating characters A, B, C or D, and then I retrieve the related implementation of the command from a map and call its execute method.</p>
  
  <p>My design was like this:</p>
  
  <pre><code>public interface Command {
      void execute();
  }
  
  public class CommandA implements Command{
    //implements execute() method
  }
  
  private Map myMap= new HashMap();
  myMap.put("A", new CommandA);
  myMap.put("B", new CommandB);
  myMap.put("C", new CommandC);
  myMap.put("D", new CommandD);
  </code></pre>
  
  <p>But, then when I read each instruction, again I have to resort to case statements:</p>
  
  <pre><code>switch(instructionFromString){
  case 'A':{myMap.get("A").execute(); break;}
  case 'B':{myMap.get("B").execute(); break;}
  case 'C':{myMap.get("C").execute(); break;}
  case 'D':{myMap.get("D").execute(); break;}
  </code></pre>
  
  <p>Obviously, somewhere along the way I managed to defeat the advantage of polymorphism against the case statements.</p>
  
  <p>Could it be the kind of data structure I selected to store my commands? It can very well be a permanent data structure to just pull those commands from. </p>
  
  <p>Another thing that comes to mind is the key/value naming that I used in my map. The way I tried to conceptually link each stored command to its associated instruction? i.e. Implementation of command "A", is stored on the map with key 'A' so it can match to the corresponding instruction "A"? That seems to me a bit unlikely though.</p>
  
  <p>Any hint or further advice about my next move to remove those case statements once and for all would be highly appreciated. Many thanks in advance</p>