title: Refactor java code
body: <p>Okay guess this question looks a lot like:</p>
  
  <p><a href="https://stackoverflow.com/questions/519422/what-is-the-best-way-to-replace-or-substitute-if-else-if-else-trees-in-programs">What is the best way to replace or substitute if..else if..else trees in programs?</a></p>
  
  <p>consider this question CLOSED!</p>
  
  <hr>
  
  <p>I would like to refactor code which looks something like this:</p>
  
  <pre><code>String input; // input from client socket.
  if (input.equals(x)) {
    doX();
  } else if (input.equals(y)) {
    doY();
  } else {
    unknown_command();
  }
  </code></pre>
  
  <p>It is code which checks input from socket to perform some action, but I don't like the <code>if else</code> construction because every time a new command is added to the server (code) a new if else has to be added which is ugly. Also when deleting a command the <code>if else</code> has to be modified.</p>