The difference between the bridge mode and the strategy mode of design mode _ design pattern

Source: Internet
Author: User

Bridging (bridge) mode is one of the structural patterns, while the policy (strategy) pattern belongs to the behavior pattern. The following are their UML structure diagrams.

Bridge mode:

Policy mode:

In bridging mode, abstraction refers to implementor by aggregation. Give an example:

Policy mode: I want to draw a circle, a solid circle, I can use Solidpen to configure, draw a dashed circle can be configured with Dashedpen. This is the strategy mode.
Bridging mode: The same is the drawing circle, I was in Windows down to draw a solid circle, with Windowpen+solidpen to configure, in UNIX to draw a solid circle on the Unixpen+solidpen to configure. If you want to draw a dashed circle under windows, use Windowspen+dashedpen to configure, to draw a dotted circle under Unix, use Unixpen+dashedpen to configure.

In the circle method, the strategy is only to consider the replacement of the algorithm, and the bridge is to consider the different platforms need to invoke different tools, the interface is only to define a method, and the implementation of the concrete implemented by the implementation class.

Difference:
Bridging mode: Not only Implementor has a change (concreteimplementor), but also abstraction can change (refinedabstraction), and the change of both is completely independent, Refinedabstraction and Concreateimplementor are loosely coupled, and they are only linked by the relationship between abstraction and implementor. Emphasizes that the Implementor interface provides only basic operations, while abstraction defines higher-level operations based on these basic operations.
Policy pattern: The change of context is not considered, only the substitution of the algorithm. It is emphasized that the strategy abstract interface provides an algorithm that is generally stateless and data-free, and the context simply calls these algorithms to complete its operation.

Therefore, the relative strategy mode, bridge mode to express more content, the structure is more complex.
The main meaning of bridge mode expression is the principle of interface isolation, that is, to distinguish the two systems which are essentially not cohesive, so that they can be loosely combined, and the strategy is only a level of an algorithm in decoupling, but not to the system level.

As can be seen from the structure diagram, the structure of the strategy pattern is contained in the bridge pattern structure, between abstraction and implementor can be considered as the strategy pattern, but the bridge mode General Implementor will provide a series of system operation, And implementor is a static structure with state and data. Also, bridging mode abstraction can be changed independently.

Reference: http://c610367182.iteye.com/blog/1965668
Http://www.blogjava.net/wangle/archive/2007/04/25/113545.html

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.