You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
561 B

package src.main.java;
/**
* 工厂类
* 根据参数创建不同的具体产品实例
*/
public class Factory {
/**
* 创建产品的静态方法
* @param type 产品类型
* @return 产品实例
*/
public static Product createProduct(String type) {
if (type == null) {
return null;
}
if (type.equalsIgnoreCase("A")) {
return new ConcreteProductA();
} else if (type.equalsIgnoreCase("B")) {
return new ConcreteProductB();
}
return null;
}
}