Proxy

Definition: The Proxy pattern provides a placeholder for another object to gain access to it.

Usage: A remote proxy controls access to a remote object. A virtual proxy controls access to a resource that is expensive to create. A protection proxy controls access to a resource based on access rights.

Example

interface WidgetlessRenderer {
	void drawTo(Graphics2D g2, int x, int y, int width, int height)
}

class ImageRendererProxy implements WidgetlessRenderer {
	ImageRendererProxy(Url url) {
		start loading image from url
	}

	void drawTo(Graphics2D g2, int x, int y, int width, int height) {
		if image is done loading
			display the image
		else
			display the text "Loading Image..."
	}
}

This class allows an image placeholder to be displayed before the image is fully loaded. This used to be standard in applets because modems couldn't download images fast enough.

Index

Copyright (C) 2008-2009 Steven Fletcher. All rights reserved.