Sitemap
Kaizen Chandra

Kaizen Chandra

Architect at @MNC

Proxy Design Pattern

2 min readFeb 14, 2026

--

Proxy design pattern provides a placeholder or surrogate object that controls access to a real object, acting as an intermediary to add functionality like lazy loading, caching, access control, or logging, without changing the real object itself. It allows the client to interact with the proxy as if it were the actual object, creating an extra layer of indirection for smarter, controlled, or remote access to resources, like an ATM (proxy) for a bank account (real object).

Press enter or click to view image in full size

Key Concepts

  • Subject Interface: Defines the common interface for both the real object and the proxy, ensuring they are interchangeable.
  • Real Subject: The actual object that performs the core business logic.
  • Proxy: The placeholder object that holds a reference to the real subject and intercepts client requests.
  • Client: Interacts with the proxy, unaware of the real subject’s direct involvement.

Get Kaizen Chandra’s stories in your inbox

Join Medium for free to get updates from this writer.

Common Uses

  • Lazy Initialization: Delaying the creation and loading of expensive objects until they are actually needed (e.g., loading large images).
  • Access Control: Controlling who can access the real object, like a protective proxy for sensitive data.
  • Logging/Caching: Adding logging or caching of results before or after delegating to the real object.
  • Remote Proxy: Managing access to objects that reside in a different address space (e.g., remote services).

Example Analogy

  • ATM: An ATM machine (proxy) manages your access to your bank account (real subject) for withdrawals and balance checks, handling the complexities of the bank system.
  • Credit Card: A debit/credit card acts as a proxy for your bank funds, allowing transactions without directly touching your cash.
// Subject
interface Image {
void display();
}

// Real Subject
class RealImage implements Image {

private String fileName;

public RealImage(String fileName) {
this.fileName = fileName;
loadFromDisk(); // heavy operation
}

private void loadFromDisk() {
System.out.println("Loading image from disk: " + fileName);
}

@Override
public void display() {
System.out.println("Displaying image: " + fileName);
}
}

// Proxy
class ProxyImage implements Image {

private RealImage realImage;
private String fileName;

public ProxyImage(String fileName) {
this.fileName = fileName;
}

@Override
public void display() {

if (realImage == null) {
realImage = new RealImage(fileName); // lazy loading
}

realImage.display();
}
}

--

--