首页 > 代码库 > DesignPattern_Creational_AbstractFactory
DesignPattern_Creational_AbstractFactory
void Main(){ AbstractFactory.ChooseFactory("A").GetProduct1().Dump(); AbstractFactory.ChooseFactory("A").GetProduct2().Dump(); AbstractFactory.ChooseFactory("B").GetProduct1().Dump(); AbstractFactory.ChooseFactory("B").GetProduct2().Dump();}interface IProduct1{}interface IProduct2{}class Product1A:IProduct1{}class Product1B:IProduct1{}class Product2A:IProduct2{}class Product2B:IProduct2{}abstract class AbstractFactory{ public static AbstractFactory ChooseFactory(string name){ switch (name) { case "A":return new FactoryA(); case "B":return new FactoryB(); default:return null; } } public abstract IProduct1 GetProduct1(); public abstract IProduct2 GetProduct2();}class FactoryA:AbstractFactory{ public override IProduct1 GetProduct1(){return new Product1A();} public override IProduct2 GetProduct2(){return new Product2A();}}class FactoryB:AbstractFactory{ public override IProduct1 GetProduct1(){return new Product1B();} public override IProduct2 GetProduct2(){return new Product2B();}}
DesignPattern_Creational_AbstractFactory
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。