原文地址:http://leihuang.org/2014/11/09/Constructors-VS-Factory-Methods/
首先看下面两者在创建对象上的区别
// instantiating a class using constructor
Dog dog = new Dog();
// instantiating the class using static method
Class Dog{
private Dog(){
}
// factory method to instantiate the class
public static Dog getInstance(){
return new Dog();
}
}
下面谈谈静态工厂方法的优缺点: