intermediate

Proxy

Place a stand-in object in front of a real subject to control access, lazy loading, caching, remote calls, or instrumentation.

Proxy stands in front of a real subject to control access, defer expensive work, cache results, enforce permissions, or instrument calls. Virtual proxies lazy-load heavy objects; protection proxies gate operations; remote proxies hide network latency details. The client should treat proxy and subject interchangeably.

On interviews: contrast Proxy with Decorator intent—control versus enrichment. Discuss caching proxies and cache invalidation ownership.

Common pitfalls: proxies that change error semantics; stale caches without TTL strategy; security proxies that check too late in the call chain.

The trade-off is flexibility versus complexity—know when the simpler path is enough.

Checklist:

  • Client depends on shared subject interface.
  • Lazy loading preserves observable behavior.
  • Cache keys and invalidation are explicit.
  • Authorization happens before side effects.