Design Pattern - Proxy

Proxy 

Definition 

A Proxy pattern is a software design that works as an interface to something else. The proxy can interface to anything, a network connection, a large object in memory, a file, or some other resource that is expensive or impossible to duplicate. In short, a proxy is a wrapper or agent object that is being called by the client to access the real serving object behind the scenes. Proxy can add extra functionality like caching. 

Types of Proxy pattern 

  • Remote proxy : Responsible for representing the object located remotely. Talking to real object might involve marshalling and unmarshalling of data and talking to the remote object. All the 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, such proxies will talk to the objects in the applications that have access to that resource and then get the result back. 
  • 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. 

Benefits of proxy 

  • Increase security by adding extra logic. 
  • Avoids duplication of objects which might be huge in size, thereby increasing the performance of the application.

Proxy with code 

Let's make a proxy that will filter out inaccessible web sites.

 

REFERENCE 

https://en.wikipedia.org/wiki/Proxy_pattern#UML_class_and_sequence_diagram

https://www.geeksforgeeks.org/proxy-design-pattern/#:~:text=Proxy%20pattern%20is%20used%20when,object's%20complexity%20from%20the%20client.&text=Remote%20proxy%3A,talking%20to%20the%20remote%20object.

Comments

Popular posts from this blog

Structures of JAVA

What is URI(URN, URL)

Spring Boot JPA - Pagination

Java Data Structures VS Python, C/C++ Data Structures

Spring Boot JPA - What is JPA, Entity, Repository