Structural 3 — Facade
In one line
One simplified entry point that hides a messy subsystem of many classes.
Think of it like this
A hotel reception desk. You say 'I need a taxi at 6 AM' and the desk talks to the taxi company, the wake-up service and the kitchen for you. One simple front door to many complex systems.
Key ideas
- 01
Solves: client coupling to a dozen classes (config, auth, retry, serialize) just to 'send a message'.
- 02
Facade is a simplified interface to a complex subsystem — not a wrapper that adds behavior.
- 03
Differs from Adapter: facade simplifies an existing system; adapter translates to a foreign interface.
Java / Spring map
- →
Spring's JdbcTemplate is a facade over JDBC/DataSource plumbing; SLF4J is a facade over logging back-ends.
Code & diagrams
One call for the controller; the orchestration of four subsystems stays in one place.
public final class CheckoutFacade {
private final InventoryClient inventory;
private final PaymentService payments;
private final OrderRepository orders;
private final NotificationService notifications;
public CheckoutFacade(InventoryClient i, PaymentService p,
OrderRepository o, NotificationService n) {
this.inventory = i; this.payments = p; this.orders = o; this.notifications = n;
}
public OrderId checkout(Cart cart, PaymentMethod method) {
Reservation r = inventory.reserve(cart.items()); // 1
try {
ChargeResult c = payments.charge(cart.total(), method); // 2
Order order = orders.save(Order.from(cart, c)); // 3
notifications.orderConfirmed(order); // 4
return order.id();
} catch (RuntimeException e) {
inventory.release(r); // compensate
throw e;
}
}
}
// Controller: checkoutFacade.checkout(cart, method); — knows nothing of the four subsystems.Explain without notes
Facade vs Adapter vs Decorator — one-line distinction for each.
Practice
Design a CheckoutFacade hiding OrderService + PaymentService + InventoryClient + EmailService.
Trade-offs
- ↔
A greedy facade can become the god class the SRP warns about. Keep it as thin orchestration with no business rules.
Completion checklist
I can explain Facade vs Adapter in one sentence each.