-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.h
More file actions
50 lines (45 loc) · 763 Bytes
/
proxy.h
File metadata and controls
50 lines (45 loc) · 763 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#pragma once
#include <iostream>
#include <string>
using namespace std;
class subject
{
public:
virtual void request() const = 0;
};
class realsub : public subject
{
public:
void request() const override
{
cout << "real subject : handle request." << endl;
}
};
class proxy : public subject
{
private:
realsub* sub;
bool check_access() const
{
cout << "proxy : checking access prior to firing a real request." << endl;
return true;
}
void log_access() const
{
cout << "proxy : logging the time of request." << endl;
}
public:
proxy(realsub* real_sub) : sub(new realsub(*real_sub)) {};
~proxy()
{
delete sub;
}
void request() const override
{
if (this->check_access())
{
this->sub->request();
this->log_access();
}
}
};