Proxy classes
Wrapper classes
Façade classes
Object-oriented programming
Design patterns

What are the differences between proxy, wrapper or a façade classes

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Proxy, wrapper, and façade classes all stand between client code and some other object or subsystem, which is why they are easy to confuse. The difference is in intent. A proxy controls access to a target, a wrapper surrounds an object to adapt or augment it, and a façade provides a simpler entry point into a more complex subsystem.

Proxy: same role, controlled access

A proxy usually presents the same interface as the real object. The client talks to the proxy as if it were the target, and the proxy decides how or when to forward the call.

Typical reasons to use a proxy include:

  • Lazy initialization
  • Access control
  • Caching
  • Logging or remote indirection
java
1interface Image {
2    void display();
3}
4
5class RealImage implements Image {
6    private final String filename;
7
8    RealImage(String filename) {
9        this.filename = filename;
10        loadFromDisk();
11    }
12
13    private void loadFromDisk() {
14        System.out.println("Loading " + filename);
15    }
16
17    public void display() {
18        System.out.println("Displaying " + filename);
19    }
20}
21
22class ImageProxy implements Image {
23    private final String filename;
24    private RealImage realImage;
25
26    ImageProxy(String filename) {
27        this.filename = filename;
28    }
29
30    public void display() {
31        if (realImage == null) {
32            realImage = new RealImage(filename);
33        }
34        realImage.display();
35    }
36}

Here the proxy controls when the expensive real object is created. The client still works with the Image interface and does not need to know whether it received a proxy or the real image.

Wrapper: a broad term for surrounding an object

"Wrapper" is more of a general description than a precise Gang of Four pattern name. A wrapper class surrounds another object and changes how you interact with it. That change may be about safety, convenience, validation, or interface adaptation.

python
1class SafeFileWrapper:
2    def __init__(self, file_obj):
3        self._file = file_obj
4
5    def write_line(self, text):
6        if not text.endswith("\n"):
7            text += "\n"
8        self._file.write(text)
9
10    def close(self):
11        self._file.close()

This wrapper does not exist mainly to control access like a proxy. It exists to add a more convenient and safer way to write lines. In everyday conversation, many decorators and adapters are also casually called wrappers because they wrap another object.

Façade: simpler interface to a subsystem

A façade is different from both proxy and wrapper because it is not mainly about one target object. It gives the client a simplified front door to a set of collaborating classes.

java
1class InventoryService {
2    boolean inStock(String sku) {
3        return true;
4    }
5}
6
7class PaymentService {
8    void charge(String accountId, int amount) {
9        System.out.println("Charging account " + accountId);
10    }
11}
12
13class ShippingService {
14    void ship(String sku) {
15        System.out.println("Shipping " + sku);
16    }
17}
18
19class OrderFacade {
20    private final InventoryService inventory = new InventoryService();
21    private final PaymentService payment = new PaymentService();
22    private final ShippingService shipping = new ShippingService();
23
24    void placeOrder(String sku, String accountId, int amount) {
25        if (!inventory.inStock(sku)) {
26            throw new IllegalStateException("Item out of stock");
27        }
28        payment.charge(accountId, amount);
29        shipping.ship(sku);
30    }
31}

The client calls one method on OrderFacade instead of coordinating several subsystem services directly. That is the hallmark of a façade: simplify a complex set of steps.

How to tell them apart quickly

A useful checklist is:

  • If the class stands in for the same interface and controls access, think proxy.
  • If the class surrounds another object to add convenience, safety, or adaptation, think wrapper.
  • If the class simplifies a larger subsystem behind one small API, think façade.

These ideas can overlap in real code, but the primary intent usually makes the pattern clear.

Common Pitfalls

The biggest mistake is classifying every forwarding class as a proxy. Delegation alone does not define the pattern; intent does.

Another issue is treating "wrapper" like a precise formal pattern when it is often just a broad descriptive term. A wrapper might behave like a decorator, adapter, or some custom helper.

Developers also confuse façade with proxy because both stand in front of something else. The difference is scope. A proxy usually fronts one target object, while a façade usually fronts a subsystem.

Finally, avoid adding these layers without a reason. Extra indirection is only useful when it makes access control, simplification, testing, or maintenance genuinely better.

Summary

  • A proxy controls access to a target object, often through the same interface.
  • A wrapper surrounds an object to adapt, simplify, or augment its behavior.
  • A façade gives clients a simpler API over a more complex subsystem.
  • Delegation alone does not tell you which pattern you have; intent does.
  • Choose the pattern that matches the problem, not the one with the most impressive name.

Course illustration
Course illustration

All Rights Reserved.