<span style="font-size:18px;">using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { ComputerBrand ss; ss = new ComputerBrandH(); ss.SetComputerOperatingSystem(new Win7() ); ss.Run (); ss.SetComputerOperatingSystem(new Win8 ()); ss.Run (); ss = new ComputerBrandL(); ss.SetComputerOperatingSystem(new Win7() ); ss.Run (); ss.SetComputerOperatingSystem(new Win8() ); ss.Run (); Console .Read (); } } //电脑的操作系统系统 abstract class OperatingSystem { public abstract void Run(); } //Win7.Win8系统等详细类 //Win7操作系统 class Win7:OperatingSystem { public override void Run() { Console.WriteLine("执行Win7系统"); } } //Win8操作系统 class Win8:OperatingSystem { public override void Run() { Console.WriteLine("执行Win8系统"); } } //电脑品牌类 //电脑品牌 abstract class ComputerBrand { protected OperatingSystem OperatingSystem; //设置电脑系统 public void SetComputerOperatingSystem (OperatingSystem OperatingSystem) { this.OperatingSystem = OperatingSystem; } //执行 public abstract void Run(); } //惠普和联想详细类 //惠普 class ComputerBrandH:ComputerBrand { public override void Run() { OperatingSystem.Run(); } } //联想 class ComputerBrandL:ComputerBrand { public override void Run() { OperatingSystem.Run(); } } } </span>在软件系统中,某些类型因为自身的逻辑,它具有两个或多个维度的变化,那么怎样应对这样的“多维度的变化”?怎样利用面向对象的技术来使得该类型可以轻松的沿着多个方向进行变化,而又不引入额外的复杂度?这个时候桥接模式就应用而生。牛郎织女通过鹊桥幸福牵手,而我们的桥接模式也在她的一方土地,起着她独特的作用......
原文:http://www.cnblogs.com/mfrbuaa/p/3894601.html