解决问题:动态决定应该创建哪一个产品的某一个子类
案例:
public interface Product {
}
public class ProductA implements Product{
}
public class ProductB implements Product{
}
public class Test{
public static void main(String[] args){
int type = 1;
Product product;
if (type == 1) {
product = new ProductA();
} else if (type == 2) {
product = new ProductB();
}
}
}