代理模式

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

 

上一篇:【笔记】常数研究


下一篇:2-路归并排序