Skip to content

门面设计模式 / Facade

门面设计模式为一个复杂的子系统提供了一个简单的接口,充当了隐藏底层实现细节的前置接口。

它通过提供高级接口,提供了一种与复杂系统交互的方便方式。

Code

javascript
class SubSystemA {
  operation() {
    console.log('SubSystemA Operation');
  }
}
class SubSystemB {
  operation() {
    console.log('SubSystemB Operation');
  }
}

class Facade {
  constructor() {
    this.subSystemA = new SubSystemA();
    this.subSystemB = new SubSystemB();
  }
  operation() {
    this.subSystemA.operation();
    this.subSystemB.operation();
  }
}

const facade = new Facade();
facade.operation();

在上述代码中,Facade 类充当了一个简化的接口,用于聚会子系统的功能