Provide a placeholder or surrogate to control access to another object. You want lazy loading or caching. You need access control or logging. Pros:
Proxy
Overview
Provide a placeholder or surrogate to control access to another object.
When to use
- You want lazy loading or caching.
- You need access control or logging.
Java example
TypeScript example
Pros and cons
Pros:
- Controls access and lifecycle.
- Useful for lazy loading and caching.
Cons:
- Extra layer to maintain.
- Can hide failures in real object creation.
Common pitfalls
- Not handling failures or retries in the proxy.
- Mixing proxy and real instance lifecycles.