-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathproxy.hpp
More file actions
37 lines (31 loc) · 725 Bytes
/
proxy.hpp
File metadata and controls
37 lines (31 loc) · 725 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
#ifndef PROXY_HPP
#define PROXY_HPP
class Image {
protected:
int myId;
Image() =default;
~Image() =default;
virtual void draw() = 0;
};
class RealImage : public Image {
public:
RealImage(int i) { myId = i; }
void draw() { cout << " drawing image " << myId << '\n'; }
};
class ProxyImage : public Image {
RealImage* realImage;
static int next;
public:
ProxyImage() {
myId = next++;
realImage = 0;
}
void draw() {
if (!realImage) {
realImage = new RealImage(myId);
}
realImage->draw();
}
};
int ProxyImage::next = 1;
#endif // PROXY_HPP