static void Main(string[] args) { try { {//BasicStructure Abstraction abstraction = new RefinedAbstraction(); abstraction.SetImplementor(new ConcreteImplementorA()); abstraction.Operation(); } {//SituationSimulation HandsetBrand huawei = new Huawei(); huawei.SetHandsetBrand(new HandsetGame()); huawei.Run("华为"); HandsetBrand xiaomi = new Xiaomi(); xiaomi.SetHandsetBrand(new HandsetGame()); xiaomi.Run("小米"); } } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.ReadKey(); }
public static void Main(string[] args) { #region Prototype Abstraction ab = new RefinedAbstraction(); ab.SetImplementor(new ConcreteImplementorA()); ab.Operation(); ab.SetImplementor(new ConcreteImplementorB()); ab.Operation(); Console.WriteLine(); #endregion Prototype HandsetBrand handsetBrand = new HandsetBrandM(); handsetBrand.SetHandsetSoft(new HandsetMp3()); handsetBrand.Run(); handsetBrand.SetHandsetSoft(new HandsetGame()); handsetBrand.Run(); handsetBrand = new HandsetBrandN(); handsetBrand.SetHandsetSoft(new HandsetAddressList()); handsetBrand.Run(); Console.ReadLine(); }
/// <summary> /// 桥接模式 /// </summary> /// <param name="args"></param> private static void Main(string[] args) { //HandsetBrand ab; //ab = new Android(); //ab.SetHandsetSoft(new HansetGame()); //ab.Run(); //ab.SetHandsetSoft(new HansetAddresslist()); //ab.Run(); //ab = new Ios(); //ab.SetHandsetSoft(new HansetGame()); //ab.Run(); //ab.SetHandsetSoft(new HansetAddresslist()); //ab.Run(); #region demo var ab = new RefinedAbstraction(); ab.SetImplementor(new ConcretelmplementorA()); ab.Operation(); ab.SetImplementor(new ConcretelmplementorB()); ab.Operation(); Console.Read(); #endregion Console.Read(); }
/// <summary> /// 基础例子 /// </summary> public static void BaseSample() { Abstraction abstraction = new RefinedAbstraction(); abstraction.SetImplementor(new ConcreteImplementorA()); abstraction.Operation(); Console.ReadKey(); }
static void Main(string[] args) { ConcreteBridgeImplementation concreteBridge = new ConcreteBridgeImplementation(); RefinedAbstraction usedAbstraction = new RefinedAbstraction(concreteBridge); usedAbstraction.Operation(); Console.WriteLine("Hello World!"); }
static void Main(string[] args) { ConcreteImplementorA concreteImplementorA = new ConcreteImplementorA(); Abstraction abstraction = new RefinedAbstraction(concreteImplementorA); abstraction.Operation(); Console.ReadKey(); }
static void Main(string[] args) { Abstraction operatorObj = new RefinedAbstraction(); operatorObj.SetImplementor(new ConcreteImplementorA()); operatorObj.Operation(); operatorObj.SetImplementor(new ConcreteImplementorB()); operatorObj.Operation(); }
static void Main(string[] args) { Abstraction ab = new RefinedAbstraction(); ab.Implementor = new ConcreteImplementorA(); ab.Operating(); ab.Implementor = new ConcreteImplementorB(); ab.Operating(); }
static void Main(string[] args) { Abstraction ab = new RefinedAbstraction(); ab.SetImplementor(new ConcreteImplementorA()); ab.Operation(); ab.SetImplementor(new ConcerteImplementorB()); ab.Operation(); Console.Read(); }
public void Run() { Console.WriteLine("Bridge Pattern ....."); Abstraction abstraction = new RefinedAbstraction(); abstraction.Implementor = new ConcreteImplementorA(); abstraction.Operation(); abstraction.Implementor = new ConcreteImplementorB(); abstraction.Operation(); }
static void Main(string[] args) { RefinedAbstraction refinedAbstraction = new RefinedAbstraction(); Implementor implementorA = new ImplementorA(); refinedAbstraction.Implementor = implementorA; refinedAbstraction.Operation(); Implementor implementorB = new ImplementorB(); refinedAbstraction.Implementor = implementorB; refinedAbstraction.Operation(); }
static void Main(string[] args) { //介绍 // 意图:将抽象部分与实现部分分离,使它们都可以独立的变化。 //主要解决:在有多种可能会变化的情况下,用继承会造成类爆炸问题,扩展起来不灵活。 //何时使用:实现系统可能有多个角度分类,每一种角度都可能变化。 //如何解决:把这种多角度分类分离出来,让它们独立变化,减少它们之间耦合。 //关键代码:抽象类依赖实现类。 //应用实例: 1、猪八戒从天蓬元帅转世投胎到猪,转世投胎的机制将尘世划分为两个等级,即:灵魂和肉体,前者相当于抽象化,后者相当于实现化。生灵通过功能的委派,调用肉体对象的功能,使得生灵可以动态地选择。 2、墙上的开关,可以看到的开关是抽象的,不用管里面具体怎么实现的。 //优点: 1、抽象和实现的分离。 2、优秀的扩展能力。 3、实现细节对客户透明。 //缺点:桥接模式的引入会增加系统的理解与设计难度,由于聚合关联关系建立在抽象层,要求开发者针对抽象进行设计与编程。 //使用场景: 1、如果一个系统需要在构件的抽象化角色和具体化角色之间增加更多的灵活性,避免在两个层次之间建立静态的继承联系,通过桥接模式可以使它们在抽象层建立一个关联关系。 2、对于那些不希望使用继承或因为多层次继承导致系统类的个数急剧增加的系统,桥接模式尤为适用。 3、一个类存在两个独立变化的维度,且这两个维度都需要进行扩展。 //注意事项:对于两个独立变化的维度,使用桥接模式再适合不过了。 HandsetBrand brand; brand = new HandsetBrandM(new HandsetGame()); brand.Run(); brand = new HandsetBrandM(new HandsetAddressList()); brand.Run(); brand = new HandsetBrandN(new HandsetGame()); brand.Run(); brand = new HandsetBrandN(new HandsetAddressList()); brand.Run(); Abstraction abstractionA = new RefinedAbstraction(new ConcreteImplementorA()); abstractionA.Operation(); Abstraction abstractionB = new RefinedAbstraction(new ConcreteImplementorB()); abstractionB.Operation(); Console.ReadLine(); }
/// <summary> /// Entry point into console application. /// </summary> private static void Main() { Abstraction ab = new RefinedAbstraction(); // Set implementation and call ab.Implementor = new ConcreteImplementorA(); ab.Operation(); // Change implemention and call ab.Implementor = new ConcreteImplementorB(); ab.Operation(); // Wait for user Console.ReadKey(); //RealWorld execution // Create RefinedAbstraction var customers = new Customers("Chicago"); // Set ConcreteImplementor customers.Data = new CustomersData(); // Exercise the bridge customers.Show(); customers.Next(); customers.Show(); customers.Next(); customers.Show(); customers.Add("Henry Velasquez"); customers.ShowAll(); // Wait for user Console.ReadKey(); }