title: AbstractClass.getInstance() method is this an anti-pattern
body: <p>In some places where a class hierarchy is present and the top most base class is an abstract class there is a static getInstance() method in the abstract class. This will be responsible for creating the correct sub-class and returning it to the caller. For example consider the below code.</p>
  
  <pre><code>public class abstract Product {
  
     public static Product getInstance(String aCode) {
         if ("a".equals(aCode) {
            return new ProductA();
         }
         return ProductDefault();
     }
     // product behaviour methods
  }
  
  public class ProductA extends Product {}
  
  public class ProductDefault extends Product {}
  </code></pre>
  
  <p>In Java, java.util.Calendar.getInstance() is one place this pattern has been followed. However this means each time a new subclass is introduced one has to modify the base class. i.e: Product class has to be modified in the above example. This seems to violate the ocp principle. Also the base class is aware about the sub class details which is again questionable.</p>
  
  <p>My question is...</p>
  
  <ol>
  <li>is the above pattern an anti-pattern ?</li>
  <li>what are the draw-backs of using the above pattern ?</li>
  <li>what alternatives can be followed instead ?</li>
  </ol>