首页 > 其他 > 详细

设计模式-桥接模式

时间:2014-11-11 08:07:52      阅读:271      评论:0      收藏:0      [点我收藏+]

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

客户端调用有多种方式

bubuko.com,布布扣
 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 }
通过构造器注入
bubuko.com,布布扣
 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框架注入的时候,非常方便

设计模式-桥接模式

原文:http://www.cnblogs.com/xqlcrystal/p/Bridge-Client.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!