Home > Web Front-end > JS Tutorial > body text

JavaScript Design Pattern Series 6: Bridge Pattern

不言
Release: 2018-04-02 14:09:10
Original
1461 people have browsed it

This article shares with you JavaScript design pattern series six: Bridge mode. Friends who are interested can take a look at

Bridge mode

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.

Give a simple example

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)
}
Copy after login

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.

Features:

  • Separate interface and implementation parts

  • Provide scalability

  • Implementation details are transparent to customers, and implementation details can be hidden from customers

Disadvantages:

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!