标签:style blog http io os ar 使用 sp on
namespace AbstractFactory.AbstractProduct { /// <summary> /// 族类A产品抽象 /// </summary> public abstract class AbstractProductA { public abstract string Name { get; } public abstract void Action(); } }
namespace AbstractFactory.AbstractFactory { /// <summary> /// 抽象工厂类 /// 提供抽象接口,用于创建抽象族类产品 /// </summary> public abstract class ProductFactory { public abstract AbstractProductA CreateProductA(); public abstract AbstractProductB CreateProductB(); } }
namespace AbstractFactory.ConcreteObject { class ProductA1 : AbstractProductA { public override string Name { get { return "ProductA1"; } } public override void Action() { Console.WriteLine("Action as Product A1"); } } }
namespace AbstractFactory.ConcreteFactory { class Factory1 : ProductFactory { public override AbstractProductA CreateProductA() { return new ProductA1(); } public override AbstractProductB CreateProductB() { return new ProductB1(); } } }
namespace AbstractFactory { class Consumer { public Consumer(ProductFactory factory) { ProductFactory = factory; ProductA = ProductFactory.CreateProductA(); ProductB = ProductFactory.CreateProductB(); } public ProductFactory ProductFactory { get; set; } public AbstractProductA ProductA { get; set; } public AbstractProductB ProductB { get; set; } public void DoSomething() { ProductA.Action(); ProductB.Action(); } } }
标签:style blog http io os ar 使用 sp on
原文地址:http://www.cnblogs.com/fecktty2013/p/designpatterns-abstractfactory.html