Design Mode learning Summary (12) Bridging Mode

Source: Internet
Author: User

This series mainly records what the design pattern intends to be, what issues it wants to solve, and when it can be used; how it solves it, master its structure diagram, remember its key code; be able to think of at least two of its application instances, one in life and one in software; What are the advantages and disadvantages of this model, and what use scenarios are there, what should I pay attention to when using it.

 

 

12. Bridging Mode


Intention: Separates the abstract part from the implementation part so that they can all change independently.
Main Solution: Inheritance may cause class explosion and the scalability is not flexible in the case of many possible changes.
When to use: The implementation system may have multiple angle classifications, and each angle may change.
Solution: Separate such multi-angle classification to allow them to change independently and reduce coupling between them.
Structure chart:

Key code: Abstract class dependency implementation class
Application Instance: 1. from Marshal tianpeng reincarnation to pig, the mechanism of reincarnation divides the world into two levels: soul and body. The former is equivalent to abstraction, and the latter is equivalent to realization. Through the assignment of functions, a creature calls the function of a physical object so that the creature can dynamically choose 2. The switch on the wall can be seen on its own. How can we implement the switch in it?
Advantages: 1. Separation of abstraction and implementation 2. excellent scalability 3. Implementation Details are transparent to customers
Disadvantages: 1. The introduction of the Bridge Mode increases the understanding and design difficulty of the system. Since the aggregation association is established on the abstraction layer, developers are required to design and program the abstraction.
Use Cases: 1. If a system requires more flexibility between the abstract role and the specific role of the component, avoid establishing static inheritance relationships between the two layers, the bridge mode enables them to establish an association at the abstraction layer. 2. The bridge mode is particularly applicable to systems that do not want to use inheritance or because of the dramatic increase in the number of system classes due to multi-level inheritance. 3. A class has two independent dimensions, which must be extended.
Notes: For two independently changed dimensions, it is no longer appropriate to use the bridge 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.