"Design mode" 7, Bridging mode

Source: Internet
Author: User

Bridge mode is to abstract the method of a class, it is not related to the extraction of factors, the development of a second class

1  PackageCom.shejimoshi.structural.Bridge;2 3 4 /**5 * Function: Bridge mode use6 * Intention: to separate the abstract part from its implementation, so that they can be independently changed7 * Applicability: You do not want to have a fixed binding relationship between the abstraction and its implementation section. 8 * The abstraction of a class and its implementation should be augmented by the method of generating subclasses9 * Modifications to an abstract implementation section should not have an impact on the customer, i.e. the customer's code does not have to be recompiledTen * You want to share the implementation across multiple objects, but at the same time ask the customer not to know this One * Time: February 17, 2016 PM 7:45:10 A * Cutter_point -  */ -  Public Abstract classsysteml the { -     //software for the corresponding system -     protectedSoft Soft; -      +      Public Abstract voidusing (); -      +      Public voidInstallsoft (Soft Soft) A     { at          This. Soft =Soft; -     } -}

1  PackageCom.shejimoshi.structural.Bridge;2 3 4 /**5 * Function: Bridge mode use6 * Intention: to separate the abstract part from its implementation, so that they can be independently changed7 * Applicability: You do not want to have a fixed binding relationship between the abstraction and its implementation section. 8 * The abstraction of a class and its implementation should be augmented by the method of generating subclasses9 * Modifications to an abstract implementation section should not have an impact on the customer, i.e. the customer's code does not have to be recompiledTen * You want to share the implementation across multiple objects, but at the same time ask the customer not to know this One * Time: February 17, 2016 PM 7:54:12 A * Cutter_point -  */ -  Public classWindowextendssysteml the { -     //default constructor -      PublicWindow () {} -      +      PublicWindow (Soft Soft) -     { +         //install the appropriate software for the system A          This. Soft =Soft; at     } -      - @Override -      Public voidusing () -     { -System.out.print ("Window System run:"); inSoft.run ();//the system runs the appropriate software -     } to      +}

1  PackageCom.shejimoshi.structural.Bridge;2 3 4 /**5 * Function: Bridge mode use6 * Intention: to separate the abstract part from its implementation, so that they can be independently changed7 * Applicability: You do not want to have a fixed binding relationship between the abstraction and its implementation section. 8 * The abstraction of a class and its implementation should be augmented by the method of generating subclasses9 * Modifications to an abstract implementation section should not have an impact on the customer, i.e. the customer's code does not have to be recompiledTen * You want to share the implementation across multiple objects, but at the same time ask the customer not to know this One * Time: February 17, 2016 PM 7:57:12 A * Cutter_point -  */ -  Public classLinuxextendssysteml the { -     //default constructor -      PublicLinux () {} -      +      PublicLinux (Soft Soft) -     { +         //install the appropriate software for the system A          This. Soft =Soft; at     } -      - @Override -      Public voidusing () -     { -System.out.print ("Linux system run:"); inSoft.run ();//the system runs the appropriate software -     } to  +}

1  PackageCom.shejimoshi.structural.Bridge;2 3 4 /**5 * Function: Bridge mode use6 * Intention: to separate the abstract part from its implementation, so that they can be independently changed7 * Applicability: You do not want to have a fixed binding relationship between the abstraction and its implementation section. 8 * The abstraction of a class and its implementation should be augmented by the method of generating subclasses9 * Modifications to an abstract implementation section should not have an impact on the customer, i.e. the customer's code does not have to be recompiledTen * You want to share the implementation across multiple objects, but at the same time ask the customer not to know this One * Time: February 17, 2016 PM 7:52:58 A * Cutter_point -  */ -  Public InterfaceSoft the { -      Public voidrun (); -}

1  PackageCom.shejimoshi.structural.Bridge;2 3 4 /**5 * Function: Compiler6 * Time: February 17, 2016 PM 7:58:177 * Cutter_point8  */9  Public classCompilerImplementsSoftTen { One  A @Override -      Public voidRun () -     { theSYSTEM.OUT.PRINTLN ("Run Compiler"); -     } -  -}

1  PackageCom.shejimoshi.structural.Bridge;2 3 4 /**5 * Function: Browser6 * Time: February 17, 2016 PM 8:00:097 * Cutter_point8  */9  Public classBrowserImplementsSoftTen { One  A @Override -      Public voidRun () -     { theSYSTEM.OUT.PRINTLN ("Run Browser"); -     } -  -}

1  PackageCom.shejimoshi.structural.Bridge;2 3 4 /**5 * Function: Test bridge mode6 * Time: February 17, 2016 PM 8:06:057 * Cutter_point8  */9  Public classTestTen { One      Public Static voidMain (string[] args) A     { -         //Our software -Soft browser =NewBrowser (); theSoft compiler =NewCompiler (); -          -         //We install the browser on the window system using the -SYSTEML win =NewWindow (); + Win.installsoft (browser); - win.using (); +          ASystem.out.println ("==============================="); at         //install the browser on Linux and the compiler -systeml Ubuntu =NewLinux (browser); - ubuntu.using (); - ubuntu.installsoft (compiler); - ubuntu.using (); -          in     } -}

Test results:

Window system run: Run browser ===============================linux system run: Run browser Linux system run: Run compiler

  

"Design mode" 7, Bridging mode

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.