Java Design Pattern serialization (7)-bridging Pattern

Source: Internet
Author: User

 

Name: Bridge Mode (refer to the bridge mode used by spring)

 

Intention: Separate the abstract part from its implementation part so that they can all change independently.

 

 

Applicability:

    • You do not want to have a fixed binding relationship between the abstraction and its implementation. For example, this may be becauseProgramThe runtime implementation part can be selected or switched.
    • Class abstraction and its implementation should be expanded by generating sub-classes. In this case, the B r I d G E mode allows you to combine different abstract interfaces and implementation parts and expand them separately.
    • The modification of an abstract implementation part should not affect the customer, that is, the customer'sCodeYou do not need to re-compile.
    • (C ++) You want to completely hide the abstract implementation part of the customer. In C ++, the class representation is visible in the class interface.
    • There are many classes to generate. Such a hierarchical structure indicates that an object must be divided into two parts. R u m B A u g h refers to this type of hierarchy as "nested generalization" (nested generalizations ).
    • You want to share the implementation among multiple objects (the reference count may be used), but the customer is not required to know this. A simple example is c o p l I e n s t r I N G class [c o p 9 2], multiple objects in this class can share the same string representation (s t r I n g r e p ).

 

Instance

 

1. Define an interface work

 
Package bridge_pattern; public interface work {public void show ();}

 

2. Define a class permission sion

 
Package bridge_pattern; Public Class Partition sion {private work; Public partition Sion (Work work) {This. Work = work;} public void theme () {work. Show ();}}

 

3. Define specific IT work itwork

 
Package bridge_pattern; public class itwork implements work {@ override public void show () {system. Out. println ("Hello this is itwork ");}}

 

4. Define a sales job sellwork

 
Package bridge_pattern; public class sellwork implements work {@ override public void show () {system. Out. println ("Hello this is sellwork ");}}

 

5. Define a test class

 

 
Package bridge_pattern; public class client {public static void main (string [] ARGs) {// display it occupation new career Sion (New itwork ()). theme (); // display the sales profession new career Sion (New sellwork ()). theme ();}}

 

Summary:

In the Spring framework, many bridging modes are used. Please make an axe!

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.