Proxy design pattern in Java
The Proxy pattern allows us to create an intermediary that acts as an interface to another resource, while also hiding the underlying complexity of the component.
Types of proxies
- Remote proxy:
They are responsible for representing the object located remotely. Talking to the real object might involve marshalling and unmarshalling of data and talking to the remote object. All that logic is encapsulated in these proxies and the client application need not worry about them.
- Virtual proxy:
These proxies will provide some default and instant results if the real object is supposed to take some time to produce results. These proxies initiate the operation on real objects and provide a default result to the application. Once the real object is done, these proxies push the actual data to the client where it has provided dummy data earlier.
- Protection proxy:
If an application does not have access to some resource then such proxies will talk to the objects in applications that have access to that resource and then get the result back.
- Smart Proxy:
A smart proxy provides additional layer of security by interposing specific actions when the object is accessed. An example can be to check if the real object is locked before it is accessed to ensure that no other object can change it.
In our case proxy controls and manage access to the object they are protecting.
Proxy UML Diagram
Proxy: An object with an interface identical to the Service. Can act as a placeholder until the Service is loaded or as gatekeeper applying extra functionality.
IService: An interface implemented by both the Proxy and Service.
Service: The actual real object that the proxy is representing.
Demo: The client application that uses and creates the Proxy.
Now, let’s move on to some example of protection proxy.
Comments
Post a Comment