设计模式--工厂模式

工厂:创建对象

解耦:在多处创建对象时,需要new多次。工厂模式将创建对象的动作抽象出来,统一进行对象的创建。

 

简单工厂模式:

public class SimpleFactory {
public static Object createBean(String beanType) {
switch (beanType) {
case type1:
return new Class1();
case type2:
return new Class2();
default:
return new ClassDefault();
}
}
}

抽象工厂模式:

  将工厂模式抽象化。

   

 

posted @ 2019-05-15 19:11  陈标  阅读(104)  评论(0编辑  收藏  举报