GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — javascript/JavaScript-Design-Patterns/The-Bridge-Pattern at master · wchaowu/javascript

Expand file tree

/

The-Bridge-Pattern

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
/

The-Bridge-Pattern

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
1 - Event listener example.js
1 - Event listener example.js
 
 
2 - Other examples of bridges.js
2 - Other examples of bridges.js
 
 
3 - Bridging multiple classes together.js
3 - Bridging multiple classes together.js
 
 
4 - Building an XHR connection queue.js
4 - Building an XHR connection queue.js
 
 
5 - XHR connection queue example page.html
5 - XHR connection queue example page.html
 
 
6 - Where have bridges been used_.js
6 - Where have bridges been used_.js
 
 
README.md
README.md
 
 

README.md

桥接模式

按照GoF的定义,桥接模式的作用在于“将抽象与其实现隔离开来,以便二者独立变化”。这种模式对于Javascript中常见的事件驱动的编程大有裨益。
桥接模式最常见和实际的应用场合之一是事件监听器回调函数。 example:事件监听器,把事件处理的语句封装到回调函数中,通过接口而不是实现进行编程。
桥接模式的其他例子:
除了在事件回调函数与接口之间进行桥接外
桥接模式也可以用于连接公开的API代码和私用的实现代码
此外,它还可以用来把多个类联结在一起。从类的角度来看,这意味着把接口作为公开的代码编写,而把类的实现作为私用代码编写。
example:用桥接模式收集某些私用性的信息
example:用桥接模式联结多个类 使用桥接模式,让Class1和Class2能够独立于BridgeClass而发生改变。
构建一个Ajax请求队列,把请求存储在浏览器内存中的一个队列 化数组中,刷新队列时,每个请求都会按“先入先出”的顺序被发送给一个后端的Web服务。
该Ajax请求队列的框架实现:example
该Ajax请求队列的使用例子:example
添加桥接方法的例子:example
这个应用程序到处都有桥接元素的身影,最明显的是,事件监听器回调函数并不直接与队列打交道,而是使用了桥接函数。
在供用户执行刷新和暂停操作的部分,我们提供了一个动作调度函数,其作用就是桥接用户操作所包含的输入信息并将其委托给恰当的处理代码。在DOM脚本编程中,这种技术也称为事件委托。click事件所代表的用户操作与DED.Queue实现完全分开的结果就是,后者的方法并不直接与那些事件耦合在一起,因此你可以在任何地方执行这些方法。
2.1、适用场合:
这里的要诀是要让接口“可桥接”,实际上也就是可适配。
2.2、优点:
把抽象与实现隔离开,有助于独立地管理软件的各组成部分。
2.3、缺点:
每使用一个桥接元素都要增加一次函数调用,这对应用程序的性能会有一些负面影响。提高了系统的复杂程度。如果一个桥接函数被用于连接两个函数,而其中某个函数根本不会在桥接函数之外被调用,那么此时这个桥接函数就不是非要不可的。
桥接模式“将抽象与实现隔离开来,以便二者独立变化”。它可以促进代码的模块化、促成更简洁的实现并提高抽象的灵活性。它可以用来把一组类和函数连接起来,而且提供了一种借助于特权函数访问私用数据的手段。
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.