外观模式
#include <iostream> #include <memory> class SubsystemA { public: void show() { std::cout << "In SubsystemA show()." << std::endl; } }; class SubsystemB { public: void show() { std::cout << "In SubsystemB show()." << std::endl; } }; class Facade { public: Facade(std::shared_ptr<SubsystemA> sa, std::shared_ptr<SubsystemB> sb) : sa(sa), sb(sb) {} void show() { std::cout << "In Facade show()." << std::endl; sa->show(); sb->show(); } private: std::shared_ptr<SubsystemA> sa = nullptr; std::shared_ptr<SubsystemB> sb = nullptr; }; int main(int argc, char *argv[]) { std::shared_ptr<SubsystemA> sa = std::make_shared<SubsystemA>(); std::shared_ptr<SubsystemB> sb = std::make_shared<SubsystemB>(); Facade f(sa, sb); f.show(); return 1; }