title: What is the most effective way of writing a factory method?
body: <p>In most of the cases when we write a factory method it is a bunch of <code>if</code> conditions which can keep on growing. What is the most effective way of writing such a method (with the least <code>if</code> conditions)?</p>
  
  <pre><code>public A createA(final String id) {
      if (id.equals("A1")) {
        return new A1();
      }
      else if (id.equals("A2")) {
        return new A2();
      }
      return null;
    }
  </code></pre>