桥接模式:当一个对象可以按照多角度去分类,并且各种分类都有可能变化时,可以采用桥接模式,将各种分类分离让他们独立变化,以减少他们之间的耦合。(各种牌子的手机游戏) #region 桥接模式 abstract class HandSetSoft { public abstract void Run(); } class HandSetGame:HandSetSoft { public override void Run() { Console.WriteLine("运行游戏软件"); } } class HandSetMedia : HandSetSoft { public override void Run() { Console.WriteLine("运行多媒体软件"); } } class HandSetAddress : HandSetSoft { public override void Run() { Console.WriteLine("运行通讯录软件"); } } abstract class HandSetBrand { protected HandSetSoft soft; public void SetHandSoft(HandSetSoft soft) { this.soft = soft; } public abstract void Run(); } class NokiaBrand : HandSetBrand { public override void Run() { soft.Run(); } } class AnyCallBrand : HandSetBrand { public override void Run() { soft.Run(); } } #endregion class Program { static void Main(string[] args) { #region 桥接模式 Console.WriteLine("桥接模式效果演示:"); HandSetBrand nokia = new NokiaBrand(); nokia.SetHandSoft(new HandSetGame()); nokia.Run(); nokia.SetHandSoft(new HandSetMedia()); nokia.Run(); #endregion } }