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;
        }
    }
}    
时间: 2024-10-12 22:54:34

DesignPattern_Creational_SimpleFactory的相关文章