Skip to content
Commitwise
Menu

Proxy pattern

A stand-in with the same interface as an object, which controls when and whether calls reach it.

Definition

A proxy can create the real object only when it's first needed (virtual proxy), check permissions (protection proxy), remember results (caching proxy) or forward calls to another machine (remote proxy). Callers can't tell it from the real object. Frameworks generate proxies for lazy ORM associations and for annotations such as @Transactional, which only work for calls that go through the proxy.

In practice

A LazyDocument shows its title from the file name and reads the file only when content() is called.

Related terms

Esc

Type to search the whole site.