When to use Proxy Design Pattern?
- Deferred Object Creation:
- Use a proxy when you want to postpone the creation of a resource-intensive object until it’s actually needed.
- This helps in optimizing the application’s startup time and resource usage.
- Access Control and Permissions:
- Use a proxy when you need to control and manage access to an object, ensuring that certain conditions or permissions are met before allowing clients to interact with the real object.
- This is particularly useful for enforcing security measures.
- Resource Optimization:
- Use a proxy to optimize the utilization of resources, such as caching results or storing previously fetched data.
- This can lead to performance improvements by avoiding redundant computations or data retrieval.
- Remote Object Interaction:
- Use a proxy when dealing with distributed systems and you want to interact with objects located in different addresses or systems.
- The proxy can handle the communication details, making remote object interaction more seamless.
Proxy Design Pattern
The Proxy Design Pattern is a structural design pattern that provides a surrogate or placeholder for another object to control access to it. This pattern is useful when you want to add an extra layer of control over access to an object. The proxy acts as an intermediary, controlling access to the real object.
A real-world example can be a cheque or credit card as a proxy for what is in our bank account. It can be used in place of cash and provides a means of accessing that cash when required.
- And that’s exactly what the Proxy pattern does – ” Controls and manages access to the object they are protecting”.
- As in the decorator pattern, proxies can be chained together. The client, and each proxy, believe it is delegating messages to the real server:
Important Topics for the Proxy Design Pattern
- Chaining of Proxies
- Components of Proxy Design Pattern
- Proxy Design Pattern example
- Why do we need Proxy Design Pattern?
- When to use Proxy Design Pattern?
- When not to use Proxy Design Pattern?