/* proxy.cpp * * Example of Proxy Pattern. */ #include class Subject { public: virtual void operation() = 0; }; class RealSubject: public Subject { public: virtual void operation() { std::cout << "RealSubject operation\n"; } }; class Proxy: public Subject { public: virtual void operation() { std::cout << "Proxy operation\n"; _real_subject.operation(); } private: RealSubject _real_subject; }; class Client { public: Client(Subject& subject) : _subject(subject) {} virtual void do_something() { _subject.operation(); } private: Subject& _subject; }; int main() { Proxy proxy; Client client(proxy); client.do_something(); }