title: Best Java design pattern to handle console commands
body: <p>I'm trying to create a console to handle console commands from a <code>string</code>. </p>
  
  <p>At the moment I'm using if statements to check for each command like this:</p>
  
  <pre><code>if (command.contains("new train")) {
      command = command.replace("new train ", "");
      Train t = new Train();
      t.setCode(command);
      ServiceProvider.getTrainService().saveOrUpdate(t);
      responeHandler("train " + command + " created");
  }
  </code></pre>
  
  <p>But this isn't the best solution in my opinion. </p>
  
  <p>I'm wondering whether there is already a good design pattern for problems like this?</p>
  
  <p>I have looked at the <code>builder</code> and <code>factory</code> patterns but can't really decide if they are the right choice.</p>