structural

Proxy

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

Problem

structural

A client needs to interact with an object indirectly because the real object may be expensive, sensitive, or remote.

Integration notes

Proxy is useful for lazy loading, access control, caching, logging, and remote service wrappers.

Tradeoffs

  • Adds another layer of indirection
  • Can make the design more complex when the extra control is unnecessary

Languages

typescript, java, python, angular, react, react-native, csharp, dotnet

Platforms

Web, Backend, Mobile, UI kits, Cross-platform systems

Variants

Scenarios

Virtual image proxy

An image viewer delays loading high-resolution images until they are actually displayed.

Language examples

Core languages

Frameworks and libraries

Virtual image proxytypescript

The virtual image proxy delays loading the real image until it is actually needed, which saves memory and startup time.

TypeScript
interface Image {
  display(): string;
}


class HighResolutionImage implements Image {
  constructor(private filename: string) {}


  display(): string {
    return `Displaying high-resolution image: ${this.filename}`;
  }
}


class ImageProxy implements Image {
  private realImage: HighResolutionImage | null = null;


  constructor(private filename: string) {}


  display(): string {
    if (!this.realImage) {
      this.realImage = new HighResolutionImage(this.filename);
    }


    return this.realImage.display();
  }
}


const image = new ImageProxy("vacation-photo.png");
console.log("Preview loaded");
console.log(image.display());

Real-world examples

  • Lazy-loaded media: Apps often defer loading large images or videos until a user actually views them.
  • Security gateways: APIs and internal systems frequently use proxy layers to verify permissions before granting access.
  • Remote API wrappers: Client libraries often act as proxies around remote services to hide networking details from callers.