Javascript design pattern system explanation and application-study notes 7-appearance pattern

Appearance mode

  • Provides a high-level interface for a group of interfaces in the subsystem
  • User uses this high-level interface

Example

  • Go to the hospital to see a doctor, the receptionist goes to register, outpatient, price, and medicine

Insert picture description here

UML class diagram
Insert picture description here

Scenes

function bindEvent(elem, type, selector, fn) {
    
    
  if (fn == null) {
    
    
    fn = selector
    selector = null
  }
  // **** 
}
// 调用
bindEvent(elem, 'click', '#div1', fn)
bindEvent(elem, 'click', fn)

Design principle verification

  • It does not conform to the single responsibility principle and the open and closed principle, so use it with caution and not abuse.

Guess you like

Origin blog.csdn.net/weixin_40693643/article/details/108839690