Design Mode learning-daily note (8. Bridge Mode)

Source: Internet
Author: User

Bridging Mode

A. Definition:

Separate the abstract part and its implementation part so that they can change independently.

B. Definition Analysis:

"ChangeAbstractIt is separated from its implementation to allow them to change independently. "Abstract: for example, if we write a GUI Tookit, there is a window class in it. This class represents the window and provides Window Function interfaces such as close, open, resize, and moveTo. the base class interface, which can be understood as an abstract part.

"ChangeAbstractAnd itsImplementationSeparation, so that they can change independently. "the implementation section, the abstract section above is the window class, implementing the window function:

Method A: Draw the outline, shape, title bar, and scroll bar of a window directly in the definition of the window class. However, there is a premise that we draw a window based on what platform, of course, it can be windows, GTK, QT, or MiniGUI. if we directly write the specific function implementation in the window class, the abstract part is the implementation part, and such implementation has a fixed dependence platform.

Another method is B: We do not directly implement the function in the window class. We inherit different subclasses from different platforms. For example, windowswindow is implemented for Windows platforms, gtkwindow is a Windows implementation for the GTK platform. such windows and gtkwindows are also implemented. they have implemented functional interface definitions in the abstract part. however, we can see that the functional interfaces in the implementation subclass are defined by window. If the subclass needs to add interfaces, the window must be dynamic. If the window is dynamic, the subclass must also be dynamic. that is, the abstract part and the implementation part are coupled, that is, there is no separation.

"ChangeAbstractAnd itsImplementationSeparated so that they can change independently. "In method B, there is a coupling between the abstract part and the implementation part because of the inheritance relationship. Is there a way to decouple it? Method C:

Implementation, that is, our windowswindow and gtkwindow do not inherit from the window class, but aggregate windows or gtkwindow to implement the window function. In this way, will the abstraction and implementation be separated? Can it be changed independently?

C. Question:

(1) Why is the bridge mode?

The abstract part and the implementation part are not inherited, but the abstract Part aggregates the implementation part. Such a link is called a bridge.

(2) When to use it?

When the abstract Part and implementation part need to be separated.

When both the abstract part and the implementation part can be expanded by generating sub-classes.

...

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.