Facade Pattern in Java (with Example)
The Facade pattern explained: put one simple method in front of a complex subsystem of many classes, hiding the mess and decoupling callers. Facade vs Adapter, Java code, UML, and when to use it.
🟢 Design Patterns · Structural · Fresher → 🟠senior
The Facade pattern gives a complicated subsystem a single, simple front door. Think of a universal remote's "Watch Movie" button: behind it, the TV turns on, the receiver switches input, the projector powers up, and the lights dim — but you press one button. In code, a Facade hides a tangle of classes behind one clean method, so callers don't need to know the messy details.
The problem
To place an order, your code must call an InventoryService, a PaymentService, a ShippingService, and a NotificationService — in the right order, handling each. Every caller that wants to "place an order" repeats this whole dance and is tightly coupled to all four classes. Change the flow, and you edit it everywhere.
The solution: one front door
🟠Wrap the subsystem in a facade that exposes one method and orchestrates the parts internally:
class OrderFacade { // the facade
private InventoryService inventory;
private PaymentService payment;
private ShippingService shipping;
private NotificationService notify;
public void placeOrder(Cart cart, Card card) { // ONE simple call
inventory.reserve(cart);
payment.charge(card, cart.total());
shipping.schedule(cart);
notify.sendConfirmation(cart.user());
}
}
// client — blissfully simple:
orderFacade.placeOrder(cart, card);
Now callers just say placeOrder(). The complexity is still there — the facade doesn't remove it — but it's hidden behind one door, and callers are decoupled from the four services.
Facade vs Adapter (they're often confused)
🟠Both wrap things, but the intent differs: Adapter makes one incompatible interface fit an expected one (translation); Facade simplifies access to a whole subsystem of many classes (convenience). Adapter changes shape; Facade reduces complexity. Stating that distinction is a clean senior signal.
Where you see it
Facades are everywhere: a service-layer method that hides a bunch of DAOs and helpers; an SDK that wraps dozens of low-level API calls behind a few friendly methods; a library like a logging or HTTP framework exposing a simple entry point over a complex engine. Any time you think "I just want one method that does the whole thing," that's a Facade.
When to use it
🟠Use Facade when a subsystem is complex and most clients only need a simple common path through it, or when you want to decouple your code from a subsystem's internals so you can change them freely. It doesn't forbid advanced users from reaching the underlying classes directly — it just offers an easy default. Don't add a facade over something that's already simple.
The interview-ready summary
"Facade puts a single simple method in front of a complex subsystem of many classes and orchestrates them internally, so clients call one entry point instead of wiring the parts. It doesn't remove complexity — it hides it and decouples callers from the internals. Unlike Adapter, which translates one incompatible interface, Facade simplifies access to a whole subsystem. I'd use it for service layers, SDKs, or any 'just do the whole thing' entry point." Concise, with the Adapter contrast."
What to read next
- Proxy Pattern — controlling access to an object
- Adapter Pattern — the pattern Facade is often confused with
- All Design Patterns (hub)
- ← The complete System Design guide (hub)