Design Mode-Bridge Mode

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.