The Bridge design pattern decouples an abstraction from its implementation so that the two can vary independently.
简单来说~ 就是要将抽象跟实作分离~ 这样他们就可以独立变化~
换句话说~ 桥梁能将抽象概念跟实作方法给鬆散耦合~ 这样就教不会互相影响
学习目标: 桥梁模式的概念及实务
学习难度: ☆☆☆
using System;namespace ConsoleApp1{ //概念定义 public class Programmer { public string name { get; set; } protected Working working; public Working Working { set { working = value; } } public virtual void Unity() { working.Unity(); } public virtual void MongoDB() { working.MongoDB(); } } //精炼概念 public class GameProgrammer : Programmer { public override void Unity() { working.Unity(); } } //精炼概念 public class DataBaseProgrammer : Programmer { public override void MongoDB() { working.MongoDB(); } } //实作抽象类 public abstract class Working { public virtual void Unity() { } public virtual void MongoDB() { } } //实作类1 public class CreateGame : Working { public override void Unity() { Console.WriteLine("Making Game"); } } //实作类2 public class ControDB : Working { public override void MongoDB() { Console.WriteLine("Control DataBase"); } } public class MainProgram { public static void Main(string[] args) { //Game工程师 Programmer gameprogrammer = new GameProgrammer(); gameprogrammer.Working = new CreateGame(); gameprogrammer.Unity(); //DB工程师 Programmer DBprogrammer = new DataBaseProgrammer(); DBprogrammer.Working = new ControDB(); DBprogrammer.MongoDB(); } }}
参考资料:
https://www.dofactory.com/net/bridge-design-pattern