Proxy Pattern
This lesson discusses how objects can act on behalf of other objects without the clients knowing they aren't talking to the intended object.
We'll cover the following
What is it ?
The literal definition of proxy is the authority to represent someone else. In a proxy pattern setup, a proxy is responsible for representing another object called the subject in front of clients. The real subject is shielded from interacting directly with the clients. There could be several reasons why one would want to front a subject with a proxy, some are listed below:
To access remote objects over the internet, running in another JVM or another address space
To protect a subject from clients not authorized to access it
To stand in place of an object that may be expensive to create and delay the object's creation till it is accessed
To cache queries or results from subject for clients
- There are a number of other use cases such as the firewall proxy, synchronization proxy etc.
Formally, the pattern is defined as a mechanism to provide a surrogate or placeholder for another object to control access to it.
Get hands-on with 1200+ tech skills courses.