Bridging (bridge) mode is one of the structural patterns, while the policy (strategy) mode 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.
To give an example:
policy mode: I want to draw a circle, to 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 am in Windows to draw a solid circle, it is configured with Windowpen+solidpen, the solid circle under UNIX is configured with Unixpen+solidpen. If you want to draw a dashed circle under windows, use Windowspen+dashedpen to configure it, and to draw a dashed circle under UNIX, use Unixpen+dashedpen to configure it.
In the circle method, the strategy only considers the substitution of the algorithm, while the bridge considers that different tools need to be called under different platforms, the interface just defines a method, and the concrete implementation is done by the concrete implementation class.
difference:
Bridging mode: Not only Implementor has a change (concreteimplementor), but abstraction can also change (refinedabstraction), and the changes are completely independent, Loosely coupled between refinedabstraction and Concreateimplementor, they are only linked by the relationship between abstraction and implementor. Stressing that the Implementor interface provides only basic operations, abstraction defines a higher level of operation based on these basic operations.
Strategy mode: Does not consider the change of context, only the substitution of the algorithm. It is emphasized that the strategy abstraction interface provides an algorithm that is generally stateless and has no data, 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, the two systems which are not cohesive in nature are distinguished from each other, so that they can be loosely combined, and the strategy is only a level of an algorithm in decoupling, not to the level of the system.
As can be seen from the structure diagram, the structure of the policy mode is inclusive in the bridge mode structure, abstraction and implementor can be considered as the policy mode, but the bridge mode General Implementor will provide a series of system operations, And implementor is a static structure with state and data. And the bridging mode abstraction can also be changed independently.
Reference: http://c610367182.iteye.com/blog/1965668
Http://www.blogjava.net/wangle/archive/2007/04/25/113545.html
The difference between the bridge pattern and the strategy mode of the design pattern