Providing a placeholder for an object using the proxy pattern
The proxy pattern is considered a placeholder that manages access to another object in order to gain control of it. The pattern may also be known by the name surrogate. The proxy pattern was described by the GoF.
Motivation
In its most general form, a proxy is a class acting as an interface to the client. A proxy is considered a wrapper or agent object that is used by a client. The client accesses the actual object through the same interface and the actual implementation stays hidden from the client in the background. Communication between the client and the implementation remains transparent, thanks to the proxy pattern.
By using a proxy, the client can access the actual object, or it can provide additional logic.
Finding it in the JDK
The proxy design pattern also has a place in the JDK. The most well-known one is the public Proxy
class, which you can find in the java.reflect
package of the java.base
module...