Facade

Providing a simple, unified interface over a complex subsystem — examples, layering, facades vs service classes, and the risk of god objects.

Beginner 1 min readLesson 10 of 24

Intent: provide a unified, simplified interface to a set of interfaces in a subsystem. The facade makes the subsystem easier to use for common cases, without hiding it from clients that need full control.

Analogy: a hotel concierge. You say "book me dinner and a taxi at 7"; the concierge deals with the restaurant, the taxi company and the timing.

ClientOrderFacadeplaceOrder(cart, user)InventoryPaymentsShippingNotifications

Example

Without a facade, every caller (web controller, mobile API, admin tool) repeats the same orchestration — and gets it subtly wrong.

public class OrderFacade {
    private final InventoryService inventory;
    private final PaymentService payments;
    private final ShippingService shipping;
    private final NotificationService notifications;

    public OrderFacade(InventoryService i, PaymentService p, ShippingService s, NotificationService n) {
        this.inventory = i; this.payments = p; this.shipping = s; this.notifications = n;
    }

    public OrderConfirmation placeOrder(Cart cart, User user) {
        Reservation r = inventory.reserve(cart.items());
        try {
            Payment pay = payments.charge(user.paymentMethod(), cart.total());
            Shipment ship = shipping.schedule(cart.items(), user.address());
            notifications.orderPlaced(user, ship.trackingId());
            return new OrderConfirmation(pay.id(), ship.trackingId());
        } catch (RuntimeException e) {
            inventory.release(r);                 // the facade owns the error handling too
            throw e;
        }
    }
}

Real-world facades

  • Libraries: requests over urllib3/sockets; jQuery over the DOM; fetch over HTTP plumbing.
  • Frameworks: Spring's JdbcTemplate over raw JDBC (connections, statements, result sets, exception translation).
  • Compilers: javac as one command over lexer, parser, type checker and code generator.
  • Application services in layered architecture: a thin layer exposing use cases over domain objects and repositories.
  • API gateways / BFFs: one simple endpoint aggregating several back-end services.
PatternInterfacePurpose
FacadeNew, simplerMake a subsystem easy to use
AdapterConverts to an existing expected interfaceMake incompatible things fit
MediatorCoordinates peers that talk through itReduce coupling between components that know each other
Key takeaways
  • Facade gives a simple entry point to a complex subsystem.
  • It orchestrates calls and error handling so clients don't repeat it.
  • The subsystem stays accessible for advanced use.
  • Keep facades thin; split them before they become god objects.