<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://blog.csdn.net/u010850027/article/details/26347757