-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProxy.java
More file actions
43 lines (36 loc) · 793 Bytes
/
Proxy.java
File metadata and controls
43 lines (36 loc) · 793 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
interface Image {
void display();
}
class RealImage implements Image {
String fileName;
public RealImage(String fileName) {
loadFromDisk(fileName);
this.fileName = fileName;
}
private void loadFromDisk(String fileName) {
System.out.println("Loading from disk " + fileName);
}
public void display() {
System.out.println("Displaying " + fileName);
}
}
class ProxyImage implements Image {
Image realImage;
String fileName;
public ProxyImage(String fileName) {
this.fileName = fileName;
}
public void display() {
if (realImage == null) {
realImage = new RealImage(fileName);
}
realImage.display();
}
}
class Test {
public static void main(String[] args) {
Image proxyImage = new ProxyImage("sky.jpg");
proxyImage.display();
proxyImage.display();
}
}