Skip to content

Commit 96244fa

Browse files
committed
Proxy - virtual proxy pattern
1 parent 06e08b8 commit 96244fa

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

Proxy/virtual-proxy.ts

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
interface Icon {
2+
getIconWidth(): number;
3+
getIconHeight(): number;
4+
paintIcon(): void;
5+
}
6+
7+
class ImageProxy implements Icon {
8+
private realImage: Image;
9+
private url: string;
10+
11+
constructor(url: string) {
12+
this.url = url;
13+
}
14+
15+
getIconWidth(): number {
16+
if (this.realImage) {
17+
return this.realImage.getIconWidth();
18+
} else {
19+
return 800;
20+
}
21+
}
22+
23+
getIconHeight(): number {
24+
if (this.realImage) {
25+
return this.realImage.getIconHeight();
26+
} else {
27+
return 600;
28+
}
29+
}
30+
31+
paintIcon(): void {
32+
if (!this.realImage) {
33+
this.realImage = new Image(this.url);
34+
}
35+
this.realImage.paintIcon();
36+
}
37+
}
38+
39+
export {};

0 commit comments

Comments
 (0)