代码
console.log('外观模式');
class ClientA {
constructor(facade) {
this.facade = facade;
}
exe() {
this.facade.fun1();
}
}
class ClientB {
constructor(facade) {
this.facade = facade;
}
exe() {
this.facade.fun2();
this.facade.fun3();
}
}
class ClinetC {
constructor(facade) {
this.facade = facade;
}
exe() {
this.facade.fun4();
}
}
class Facade {
constructor() {
this.innerfun1 = new Fuction1();
this.innerfun2 = new Fuction2();
this.innerfun3 = new Fuction3();
}
fun1() {
this.innerfun1.exe();
}
fun2() {
this.innerfun2.exe();
}
fun3() {
this.innerfun3.exe();
}
fun4() {
this.innerfun3.exe2();
}
}
class Fuction1 {
exe() {
console.log("机能1");
}
}
class Fuction2 {
exe() {
console.log("机能2");
}
}
class Fuction3 {
exe() {
console.log("机能3");
}
exe2() {
console.log("机能4");
}
}
// 客户端
class Client {
main() {
var fac = new Facade();
var clienta = new ClientA(fac);
clienta.exe();
var clientb = new ClientB(fac);
clientb.exe();
var clientc = new ClinetC(fac);
clientc.exe();
}
}
var client = new Client();
client.main();