Skip to content

Commit

Permalink
Create Proxy Pattern
Browse files Browse the repository at this point in the history
Signed-off-by: Junzhuo Du <[email protected]>
  • Loading branch information
Junzhuo Du committed Feb 28, 2020
1 parent 2484bf3 commit 994dd25
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 76 deletions.
76 changes: 0 additions & 76 deletions StructuralPatterns/proxy/Proxy.cpp

This file was deleted.

54 changes: 54 additions & 0 deletions StructuralPatterns/proxy/Proxy.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* C++ Design Patterns:
* Author: Junzhuo Du [github.com/Junzhuodu]
* 2020
*
*/

#include <iostream>

class Subject {
public:
virtual ~Subject() {}

virtual void request() = 0;
};

class RealSubject : public Subject {
public:
void request() {
std::cout << "RealSubject Request" << std::endl;
}
};

class Proxy : public Subject
{
public:
Proxy()
{
subject = new RealSubject();
}

~Proxy()
{
delete subject;
}

void request()
{
subject->request();
}

private:
RealSubject *subject;
};


int main()
{
Proxy *proxy = new Proxy();
proxy->request();

delete proxy;
return 0;
}

0 comments on commit 994dd25

Please sign in to comment.