Design Mode-Bridge Mode
Bridge: separates abstract and implementation parts so that they can all change independently. Understanding: To solve the problem of changing an object and affecting multiple objects, we need to abstract specific objects so that the coupling between objects and change factors can be reduced and the maintainability and scalability of the system can be improved. For example, the mobile phone system ecosystem problem: As we all know, the wp ecosystem is relatively inferior to some systems. You need to work hard. Nokia will step down from the altar, and wp will go up to the altar. Wp/ios system class: The running software that can carry any software in the current running environment. If a new system is added, the software must make a new system version weixin/kuwo: start to run the software, if a new piece of software is added, many system versions are required. Implementation: run different software in iso and wp systems. Software code: Copy code // software public interface ISoftWare {void start () ;}// Kuwo public class Kuwo: ISoftWare {public void start () {Console. writeLine ("listen to music, use cool! ") ;}}// WeiXin public class WeiXin: ISoftWare {public void start () {Console. WriteLine (" brings you closer to me! ") ;}} Copy the code operating System code copy the code // operating System, Run the software public abstract class System {public abstract void Run (ISoftWare software );} // Wp public class WinPhone: System {public override void Run (ISoftWare software) {Console. writeLine ("Winphone system, give you what you want;"); software. start () ;}// Ios public class Ios: System {public override void Run (ISoftWare software) {Console. writeLine ("Ios system, unexpected;"); software. start () ;}} Code client code copy code public static void Main () {ISoftWare weixin = new WeiXin (); ISoftWare kuwo = new Kuwo (); // Wp System WpSys = new WinPhone (); wpSys. run (weixin); WpSys. run (kuwo); // IOS System IosSys = new Ios (); IosSys. run (weixin); IosSys. run (kuwo); Console. conclusion 1: participants in the bridge mode include: abstract class: Define the interface class of the class: Inherit the abstract class, and implement extension: the specific implementation of interfaces is as follows: interface implementation Class 2. The function system of the bridge mode. The software is like two layers, which can avoid the establishment of highly coupled links between the two layers, at the same time, abstract and implementation separation are also implemented, so that the system and software do not change Will be affected by the other party, and it is easier to hide the implementation details from the client program.