外观模式

#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;
}

 

上一篇:Go 实现的数学表达式解析计算引擎 math-engine


下一篇:Swift之深入解析如何进行多重条件排序