设计模式-桥接模式

桥接模式客户端调用

关于桥接模式大家都很熟悉,设计模式书上也介绍的非常清楚,但介绍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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值