Implementing a Proxy

Implementing a proxy is straightforward. Depending on which proxy variant you're implementing (see the preceding section), you'll customize the steps to the variant.

Step 1: Identify access control responsibilities

Start by identifying all the access responsibilities of the server and assigning them to the proxy component.

Step 2: Introduce an abstract base class

When your language supports inheritance, it's useful to introduce a base class, AbstractServer, described earlier in this chapter and shown in Figure 19-1. Both the server and the proxy inherit the access responsibilities from the abstract base class.

images

You can use the Adapter pattern (from Design Patterns: Elements of Reusable Object-Oriented Software) to adapt among the interfaces if the server and the proxy can't have identical interfaces that they inherit from the abstract base class.

images

If your language doesn't support inheritance, consider defining the interface in a library or module that can be shared to help keep the interfaces all the same.

Step 3: Implement the proxy's functions

In this step, you implement the responsibilities that you identified for the proxy in Step 1. You implement both the access functionality that you're removing from the server to place into the proxy and also the mechanisms ...

Get Pattern-Oriented Software Architecture For Dummies now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.