一、静态工厂
通过工厂类的静态方法来获取实例对象
public class FruitFactory {
public static Fruit getInstance(){
return new Fruit();
}
public static void main(String[] args) {
FruitFactory.getInstance();
}
}
二、实例工厂
先创建工厂类的对象,然后通过该对象去调用生产实例对象的方法
public class FruitFactory {
public Fruit getInstances(){
return new Fruit();
}
public static void main(String[] args) {
FruitFactory fruitFactory = new FruitFactory();
fruitFactory.getInstances();
}
}