首页 > 代码库 > DesignPattern_Creational_SimpleFactory

DesignPattern_Creational_SimpleFactory

void Main(){    SimpleFactory.GetProduct("A").Dump();    SimpleFactory.GetProduct("B").Dump();}class Product{}class ProductA:Product{}class ProductB:Product{}class SimpleFactory{    public static Product GetProduct(string name){        switch (name)        {            case "A":return new ProductA();            case "B":return new ProductB();            default:return null;        }    }}    

 

DesignPattern_Creational_SimpleFactory