Design Patterns Java™ Workbook

(Michael S) #1

Chapter 11. Proxy...........................................................................................................................................


Chapter 11. Proxy


An ordinary object does its own work in support of the public interface that it advertises. It
can happen, though, that a legitimate object cannot live up to this ordinary responsibility. This
occurs most frequently when an object takes a long time to load or when the object is running
on another computer. In these cases, a proxy object can take the responsibility that a client
expects and forward the request appropriately to an underlying target object. The intent of the
PROXY pattern is to provide a surrogate, or placeholder, for another object to control access to
it.


A Classic Example: Image Proxies...........................................................................................................


While conducting plant tours, the Oozinoz public relations manager wants to pause at one
point to show images of previous exhibitions. Your design team decides to satisfy this
requirement with a PC-based Java application with a Swing GUI. You might convert to a
browser-based thin-client design in the future, but in any case, you can rely on Java's
extensive support for loading, manipulating, and displaying images.


As you start constructing the application, realize that you will want to load some images only
on demand. You might make clickable, thumbnail versions of larger images, but in the first
pass, you decide to show prebuilt Absent and Loading... images. Figure 11.1 shows three
screen shots of the system you intend to construct. (The code that displays the windows that
Figure 11.1 shows is in the ShowProxy class in the com.oozinoz.applications
package. The underlying code that supports the application is in the
com.oozinoz.imaging package.)

Free download pdf