Bridge mode of design pattern

Source: Internet
Author: User

Bridge mode is also a structural design pattern, understood from the name, like the connection of two elements of a pattern, it is almost understandable, but the bridge mode is not as adaptable as the adapter mode of the two classes.

The abstraction and realization of bridge mode connection, in order to achieve the purpose of abstraction and realization of both parts, must be achieved by using the polymerization of the bridge. The abstract and implementation parts here are not the relationship between the abstract parent class and the implementation subclass that we usually think of, but the combination. The implementation part is called by the abstract part to complete (implement) the function of the abstract part.

System design, always full of variables, then what kind of design can be better to solve the impact of changes to the system? In general, the principle of design is to use the immutable framework to define the abstract class, and then to implement the content of the variable easily using the specific subclass. This is an abstract class that is used in the face of customers, and when needed, changes by adding new implementation subclasses, thereby narrowing the impact of the change. But this can lead to a growing number of subclasses and, in many cases, not enough flexibility.

When there are similar behaviors on the implementation subclass, we might as well extract these behaviors, open the call in an interface, and then provide the service to the original subclass in a composite way.

This is the idea of bridge mode, and let's look at an example class diagram of the bridge pattern to deepen our understanding.

From this example, we can see that not only the implementation of the interface provided by the partial and abstract parts may be completely different, but also the implementation of internal and abstract parts of the inner interface can be completely different.

The bridge model has its own adaptation of the use environment:

1, when your system has more than one place to reuse similar behavior, or a combination of several similar behaviors, bridge mode can effectively reduce the resulting sub-class due to the difference in behavior

2, the behavior of a class in the system may have several different trends, in order to effectively encapsulate the changes, you can consider the behavior of the class to extract

The combination of low coupling in bridge mode achieves good flexibility and is a good design model for decoupling.

Bridge mode of design pattern

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.