1.普通工厂方法模式:普通工厂方法属于工厂方法模式,它是同个方法,根据传入的参数不同,创建不同对象实例(这些对象实例都实现了同一个接口)
2.简单实例如下:
/** * @ClassName CommonFactory * @Description 普通工厂模式(属于工厂方法模式):通过单个方法创建实现了同个接口的不同实例 * @Author hs * @Date 2021/1/31 13:42 * @Version 1.0 */ public class CommonFactory { public Map produce(int type){ if(type==1){ return new HashMap(); } if(type==2){ return new TreeMap(); } if(type==3){ return new LinkedHashMap(); } return null; } }