Proxy

The Proxy Pattern provides a surrogate/placeholder for another object with the intent of providing an extra layer of access control.

In Object-Oriented languages, the access control to an object is normally achieved exposing a different interface to the client accordingly to its privilege. In Java we have private, protected, package, an public modifiers that could be used for this purpose.

Sometimes this is not enough. We want to rule the access to our object in a way that is not achievable through the standard OO schema.

In the case of the remote proxy, the point is different. There we just want to hide to the user object the complexity of accessing a remote object, exposing locally the same interface of the object it needs.

In any case, the idea of a proxy is that we have an interface (named Subject in this context) that is implemented by both the RealSubject (the object's class the client wants to access) and Proxy.

Since the actual interface is the same, and since we should strive to program to interfaces, from the point of view of the client there is little or almost no difference between using the RealSubject or the Proxy. So we can safely hide in the proxy all the functionality we are required to provide to the client.

Chapter eleven of Head First Design Patterns, is about proxy. I suggest you to get the book to have more information on the matter.

No comments:

Post a Comment