Java and mode Learning Series-Bridge Mode

Source: Internet
Author: User

 

I, Structure of Bridge Mode

The purpose of the bridge model is to use a combination/aggregation relationship between the abstraction and implementation of a software system, rather than an inheritance relationship (inheritance is a strong coupling), so that the two can change relatively independently. Bridge mode is a weak coupling solution based on aggregation relationships.

The structure is as follows:

II, Application of Bridge Mode in Java

AWTPeerArchitecture

Java provides a peer component for every GUI component in AWT. This peer component is implemented by the Java component in the local environment. For example, choice is a GUI component provided by AWT. It allows you to select one or more items in a column. Developers of a Java application only need to consider that the choice object is dynamically associated with a suitable underlying peer object. This peer object performs the correct operation according to the instruction. This interface connects the GUI component of Java with the peer component of the local environment, which is called the peer interface. A peer interface is actually an interface that defines the methods that must be implemented by peer components.

Each Java component is a subclass of the component type, and each peer component is a subclass of the componentpeer type. They communicate with each other through toolkit objects, which is the application of the bridge mode.

JDBCDrive

Most drivers are used in Bridge Mode.

III, Relationship between the bridge mode and other modes

Adapter Mode

The bridge mode is similar to the adaptation mode, but the adapter mode aims to change the existing interfaces so that they can be compatible so that the two unrelated classes can work together. The Bridge Mode separates abstraction and implementation, so that the interfaces of the two can be different.

4. Under what circumstances does the Bridge Mode work?

1. If a system needs to increase more flexibility between the abstract role and the specific role of the component, avoid establishing static connections between the two layers.

2. The design requires that any change to the role should not affect the client, or the change to the role should be completely transparent to the client.

3. If a component has more than one abstract role and actual role, the system must dynamically couple them.

4. Although there is no problem in using inheritance in the system, abstract roles and specific roles need to be changed independently, and design requirements need to be managed independently.

 

 

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.