

























关于桥接模式大家都很熟悉,设计模式书上也介绍的非常清楚,但介绍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框架注入的时候,非常方便
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。