-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Junzhuo Du <[email protected]>
- Loading branch information
Junzhuo Du
committed
Feb 28, 2020
1 parent
2484bf3
commit 994dd25
Showing
2 changed files
with
54 additions
and
76 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |