Example: Client-Proxy-Server Collaboration

Structure

In the unadorned client-server collaboration a client object requests a service from a server object (by invoking a method or sending a message) and the server returns a result to the client:

result = server.service(args);

A proxy sits between a client and server. It implements the same interface as the server and from the client's perspective is indistinguishable from the server. The proxy can enhance the services of the server by pre-processing the client's request and/or post-processing the server's result. Between pre and post processing the proxy forwards the client's request to its peer, which may be the actual server or yet another proxy in a chain.

An example is a cache proxy, which searches a cache for the requested result before forwarding the request to its peer. More concretely, if the client is a web browser requesting a web page, and if the same web page was recently requested by the browser, then the web page may still be in the proxy's cache. In this case the cached result is returned to the client without the need to forward the request to the server.

The following class diagram shows the structure of the Client-Proxy-Server collaboration:

Interactions

The following interactions assume a client object invokes serviceA of its server:

page = server.servicedA(url);

Unbeknownst to the client the server is a cache proxy which first checks its cache before forwarding the request to the actual server.

Interaction 1: Result Cached

The first interaction assumes the result of serviceA is found in the proxy's cache:

Interaction 2: Page Uncached

Interaction 3: Using a Combined Fragment

 

Interaction 3: Using a Combined Fragment and Interaction Use References