外观模式定义
为复杂系统提供一个简化接口,它通过创建一个高层接口(外观),将多个子系统的复杂操作封装起来,以便客户端更容易使用。
简单实现
#include<iostream>// 子系统类
class SubsystemA {
public:void operationA() {std::cout << "Subsystem A operation" << std::endl;}
};class SubsystemB {
public:void operationB() {std::cout << "Subsystem B operation" << std::endl;}
};class SubsystemC {
public:void operationC() {std::cout << "Subsystem C operation" << std::endl;}
};// 外观类
class Facade {
public:void operation() {subsystemA.operationA();subsystemB.operationB();subsystemC.operationC();}private:SubsystemA subsystemA;SubsystemB subsystemB;SubsystemC subsystemC;
};int main() {Facade facade;facade.operation();return 0;
}