Zachary W. Huang

Home Projects Blog Guides Resume

Facade

Idea: provide a unified, high-level interface to reduce complexity (typically involving multiple separate subsystems).

class SubsystemA {
  doThing() {
    console.log("A");
  }
}

class SubsystemB {
  doThing() {
    console.log("B");
  }
}

class SubsystemC {
  doThing() {
    console.log("C");
  }
}

class Facade {
  doThing() {
    const thingA = new SubsystemA();
    const thingB = new SubsystemB();
    const thingC = new SubsystemC();
    thingA.doThing();
    thingB.doThing();
    thingC.doThing();
  }
}

function main() {
  // the client does not have to know about each underlying subsystem
  const facade = new Facade();
  facade.doThing(); // "A  B  C"
}
RSS icon github logo linkedin logo

Zachary W. Huang © 2021-2024