Talk:Proxy pattern
Appearance
![]() | Computing Unassessed | |||||||||
|
![]() | Computer science Start‑class Mid‑importance | ||||||||||||||||
|
proxy
Isn't the Firewall proxy the same as Protection proxy? no91.186.200.21 12:51, 11 November 2007 (UTC)
ProxyImage code is overengineered
import java.util.*;
class RealImage {
private String filename;
private Image image;
public RealImage(String filename) { this.filename = filename; }
public void displayImage() {
if (image == null) {
loadImageFromDisk(); // load only on demand
}
// Display image code here.
}
private void loadImageFromDisk() {
// Potentially expensive operation
// ...
// initializes image object
System.out.println("Loading "+filename);
}
}
class ProxyExample {
public static void main(String[] args) {
RealImage image1 = new RealImage("HiRes_10MB_Photo1") );
RealImage image2 = new RealImage("HiRes_10MB_Photo2") );
image1.displayImage(); // loading necessary
image2.displayImage(); // loading necessary
image2.displayImage(); // no loading necessary; already done
// the third image will never be loaded - time saved!
}
}
The proxy pattern isn't needed at all!!! Diegofd (talk) 16:11, 16 May 2008 (UTC)
Copyright violation?
This edit seems a copyright violation from http://userpages.umbc.edu/~tarr/dp/lectures/Proxy.pdf (4/4/2004; 69 KB) the date of pdf is set before the edit Lusum (talk) 11:23, 11 June 2008 (UTC)
Mistake in example?
Current version:
class ProxyImage implements Image {
private String filename;
private Image image;
public ProxyImage(String filename) { this.filename = filename; }
public void displayImage() {
if (image == null) {
image = new RealImage(filename); // load only on demand
}
image.displayImage();
}
}
Can interfaces such as "Image" be used as types?
Would this (still) be correct?
class ProxyImage implements Image {
private String filename;
private RealImage image;
public ProxyImage(String filename) { this.filename = filename; }
public void displayImage() {
if (image == null) {
image = new RealImage(filename); // load only on demand
}
image.displayImage();
}
}
Notice the difference between private Image image;
and private RealImage image;
.
Thanks, Abdull under IP --134.91.225.10 (talk) 16:24, 18 September 2008 (UTC)