设计模式-桥接模式

关于桥接模式大家都很熟悉,设计模式书上也介绍的非常清楚,但介绍Client调用的不多

客户端调用有多种方式

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Text;
 4 using DesignPattern.Bridge;
 5 
 6 namespace DesignPattern
 7 {
 8     class Program
 9     {
10         static void Main(string[] args)
11         {
12             Abstraction a = new RefinedAbstraction(new ConcreteImplementor());
13             a.Operation();
14             
15         }
16     }
17 }
通过构造器注入
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Text;
 4 using DesignPattern.Bridge;
 5 
 6 namespace DesignPattern
 7 {
 8     class Program
 9     {
10         static void Main(string[] args)
11         {
12             Abstraction a = new RefinedAbstraction();
13             a.Imp = new ConcreteImplementor();
14             a.Operation();
15             
16         }
17     }
18 }
Set注入

 两种方式都可以实现注入真正的实现类,但是Set方式要稍好些,以后再更换为类似Spring框架注入的时候,非常方便

原文地址:https://www.cnblogs.com/xqlcrystal/p/Bridge-Client.html