Proxy is a structural design pattern that lets you provide a substitute or placeholder for another object. A proxy controls access to the original object, allowing you to perform something either before or after the request gets through to the original object.
-
The Service Interface declares the interface of the Service. Theproxy must follow this interface to be able to disguise itself as a service object.
-
The Service is a class that provides some useful business logic.
-
The Proxy class has a reference field that points to a service object. After the proxy finishes its processing (e.g., lazy initialization, logging, access control, caching, etc.), it passes the request to the service object. Usually, proxies manage the full lifecycle of their service objects.
-
The Client should work with both services and proxies via the same interface. This way you can pass a proxy into any code that expects a service object.
Image and Description source: Dive Into DESIGN PATTERNS by Alexander Shvets
Link to the book : https://refactoring.guru/design-patterns/book