设计模式之 简单工厂模式

interface Product {
    
}

class Product1 implements Product{

}

class Product2 implements Product{

}

public class SimpleFactory {
    public static Product createProduct(String productname) {
        if (productname == "1") {
            return new Product1();
        } else if (productname == "2") {
            return new Product2();
        } else {
            return null;
        }
    }
}
原文地址:https://www.cnblogs.com/zhonghan/p/3119154.html