Proxy is most useful when there is a real object behind the wrapper and access to that object needs a policy.
Strong Java Use Cases
- lazy loading expensive resources
- security and authorization wrappers
- remote client stand-ins
- repository or service caching proxies
- generated framework proxies around interfaces
Weak Use Cases
Proxy is weak when:
- there is no distinct access concern
- the wrapper is just a vague service layer rename
- the real object is not meaningfully different from the wrapper
Review Questions
- What access concern does the proxy enforce?
- Would callers benefit from knowing about remoteness or latency explicitly?
- Is this clearer as a proxy or as a decorator/interceptor?
Proxy earns its place when access itself is the thing being designed.