The Proxy design pattern is a class functioning as an interface to another class or object. A Proxy could be for anything, such as a network connection, an object in memory, a file, or anything else you need to provide an abstraction between.
Types of proxies,
-
Virtual Proxy: An object that can cache parts of the real object, and then complete loading the full object when necessary.
-
Remote Proxy: Can relay messages to a real object that exists in a different address space.
-
Protection Proxy: Apply an authentication layer in front of the real object.
-
Smart Reference: An object whose internal attributes can be overridden or replaced.
Output: as you can see in the first call, it took the data from post management and brought it, then brought it from the cache.
- A virtual proxy can cache elements of a real subject before loading the full object into memory.. With the memory saving technique, The advantage of this approach is a faster application start-up time, as it is not required to created and load all of the application objects.
In general, objects in an application interact with each other to implement the overall application functionality. Most application object are generally accessible to all other objects in the application. At times, it may be necessary to restrict the accessibility of an object only to a limited set of client objects based on their access rights. When a client object tries to access such an object, the client is given access to the services provided by the object only if the client can furnish proper authentication credentials. In such cases, a separate object can be designated with the responsibility of verifying the access privileges of different client objects when they access the actual object. In other words, every client must successfully authenticate with this designated object to get access to the actual object functionality. Such an object with which a client needs to authenticate to get access to the actual object can be referred as an object authenticator which is implemented using the Protection Proxy.
Output: Thanks to the protection proxy, we made the authorization restriction thanks to the interfaces.
- A protection proxy can provide an authentication layer. For example, an NGINX proxy can add Basic Authentication restriction to an HTTP request.