This article shares with you JavaScript design pattern series six: Bridge mode. Friends who are interested can take a look at
Bridge (Bridge) is used to The decoupling of abstraction and realization allows the two to change independently. This type of design pattern is a structural pattern, which achieves the decoupling of the two by providing a bridging structure between abstraction and realization.
var Fn1 = function(a) { // dosomething... } var Fn2 = function(b) { // dosomething... } var Bridge = function(a, b){ this.one = new Fn1(a) this.two = new Fn2(b) }
To have an implementation, you must first have an interface. The implementation must correspond to the interface, but the implementation is not necessarily bound to an interface. We can combine existing The interface method is used to form a new implementation to correspond to new requirements. There is no need to redefine the interface and rewrite an implementation for the new interface.
So interfaces and implementations can be combined. This combination is called bridge mode. Mainly used when starting to design the system.
Separate interface and implementation parts
Provide scalability
Implementation details are transparent to customers, and implementation details can be hidden from customers
A large number of classes will lead to an increase in development costs, and at the same time, performance may also be compromised Will be reduced
Related recommendations:
JavaScript Design Pattern Series 2: Singleton Mode
JavaScript Design Pattern Series 4: Prototype model
The above is the detailed content of JavaScript Design Pattern Series 6: Bridge Pattern. For more information, please follow other related articles on the PHP Chinese website!