其他分享
首页 > 其他分享> > 外观模式

外观模式

作者:互联网

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

 

标签:std,外观,show,模式,sb,shared,sa,ptr
来源: https://www.cnblogs.com/qiandeheng/p/15937181.html