creational

Proxy

Provide a surrogate or placeholder for another object to control access to it.

Sometimes you need to govern access to an object — to delay its expensive creation, check permissions, cache its results, or log every call — without changing the object itself or the code that uses it. Proxy puts a stand-in between client and target that shares the target's interface, so the client is none the wiser while the proxy quietly inserts control around each call.

A credit card is a proxy for your bank account — same 'pay' interface but adds authorization and logging.

Key Concepts

1
Because the proxy implements the same interface as the real subject, the client talks to it exactly as it would the real thing. The proxy holds a reference to the real object (or the means to create one) and decides, per call, whether to handle the request itself, modify it, or forward it. The variations are named by intent: a virtual proxy defers creating a heavyweight object until it's first needed; a protection proxy enforces access rules before delegating; a caching proxy memoises expensive results; a remote proxy represents an object living in another process or machine; and a logging proxy records calls for auditing.
2
It is a natural fit for lazy initialisation, access control, transparent caching, and instrumentation — Hibernate's lazy entities and Spring's AOP proxies are everyday examples. Proxy looks structurally like Decorator and Adapter but differs in purpose: Decorator adds behaviour, Adapter converts an interface, Proxy controls access while keeping the same interface. The main caution is that hiding work behind an innocuous-looking call — a network hop, a cache miss — can surprise callers, so the proxy's behaviour should stay predictable.