代理模式

#include <iostream>
#include <memory>

class Subject {
public:
    virtual void show() = 0;
};

class RealSubject : public Subject {
public:
    void show() override { std::cout << "In RealSubject show()." << std::endl; }
};

class Proxy : public Subject {
public:
    void show() override {
        std::cout << "In Proxy show()." << std::endl;
        rs.show();
    }
private:
    RealSubject rs;
};

int main(int argc, char *argv[]) {
    std::unique_ptr<Subject> s = std::make_unique<Proxy>();
    s->show();
    return 1;
}

  

posted @ 2022-02-25 17:54  南乡水  阅读(13)  评论(0编辑  收藏  举报