设计模式学习笔记--桥接模式

 1 using System;
 2 
 3 namespace Bridge
 4 {
 5     /// <summary> 
 6     /// 作者:bzyzhang
 7     /// 时间:2016/5/31 7:19:03 
 8     /// 博客地址:http://www.cnblogs.com/bzyzhang/
 9     /// Implementor说明:本代码版权归bzyzhang所有,使用时必须带上bzyzhang博客地址 
10     /// </summary> 
11     public abstract class Implementor
12     {
13         public abstract void Operation();
14     }
15 }
View Code
 1 using System;
 2 
 3 namespace Bridge
 4 {
 5     /// <summary> 
 6     /// 作者:bzyzhang
 7     /// 时间:2016/5/31 7:20:35 
 8     /// 博客地址:http://www.cnblogs.com/bzyzhang/
 9     /// ConcreteImplementorA说明:本代码版权归bzyzhang所有,使用时必须带上bzyzhang博客地址 
10     /// </summary> 
11     public class ConcreteImplementorA:Implementor
12     {
13         public override void Operation()
14         {
15             Console.WriteLine("具体实现A的方法执行");
16         }
17     }
18 }
View Code
 1 using System;
 2 
 3 namespace Bridge
 4 {
 5     /// <summary> 
 6     /// 作者:bzyzhang
 7     /// 时间:2016/5/31 7:21:25 
 8     /// 博客地址:http://www.cnblogs.com/bzyzhang/
 9     /// ConcreteImplementorB说明:本代码版权归bzyzhang所有,使用时必须带上bzyzhang博客地址 
10     /// </summary> 
11     public class ConcreteImplementorB:Implementor
12     {
13         public override void Operation()
14         {
15             Console.WriteLine("具体实现B的方法执行");
16         }
17     }
18 }
View Code
 1 using System;
 2 
 3 namespace Bridge
 4 {
 5     /// <summary> 
 6     /// 作者:bzyzhang
 7     /// 时间:2016/5/31 7:22:21 
 8     /// 博客地址:http://www.cnblogs.com/bzyzhang/
 9     /// Abstraction说明:本代码版权归bzyzhang所有,使用时必须带上bzyzhang博客地址 
10     /// </summary> 
11     public abstract class Abstraction
12     {
13         protected Implementor implementor;
14 
15         public void SetImplementor(Implementor implementor)
16         {
17             this.implementor = implementor;
18         }
19 
20         public virtual void Operation()
21         {
22             implementor.Operation();
23         }
24     }
25 }
View Code
 1 using System;
 2 
 3 namespace Bridge
 4 {
 5     /// <summary> 
 6     /// 作者:bzyzhang
 7     /// 时间:2016/5/31 7:24:16 
 8     /// 博客地址:http://www.cnblogs.com/bzyzhang/
 9     /// RefinedAbstraction说明:本代码版权归bzyzhang所有,使用时必须带上bzyzhang博客地址 
10     /// </summary> 
11     public class RefinedAbstraction:Abstraction
12     {
13         public override void Operation()
14         {
15             implementor.Operation();
16         }
17     }
18 }
View Code
 1 namespace Bridge
 2 {
 3     class Program
 4     {
 5         static void Main(string[] args)
 6         {
 7             Abstraction ab = new RefinedAbstraction();
 8 
 9             ab.SetImplementor(new ConcreteImplementorA());
10             ab.Operation();
11 
12             ab.SetImplementor(new ConcreteImplementorB());
13             ab.Operation();
14         }
15     }
16 }
View Code
原文地址:https://www.cnblogs.com/bzyzhang/p/5544611.html