GoF pattern • Structural
GoFStructuralJava example
Facade solves a specific structural problem in the design.
Provide a simpler entry point to a complicated subsystem.
Pattern overview
GoF pattern
Provide a simpler entry point to a complicated subsystem.
Intent
Offer a unified, higher-level interface that makes a subsystem easier to use.
Problem
Clients need a common task completed, but the subsystem requires many low-level calls and coordination details.
Solution
Introduce a facade that exposes a focused workflow-oriented API while hiding the subsystem complexity.
Fit and tradeoffs
FamilyGoF
CategoryStructural
Best used when
- When you want a stable application-facing API over complex internals.
- When onboarding cost is high because subsystems are too detailed.
Tradeoffs
- Can become a god object if it absorbs too many workflows.
- May hide useful subsystem capabilities if too narrow.
Java example
This example is intentionally compact so the pattern shape stays easy to see.
final class CheckoutFacade {
private final CartService cartService;
private final PricingService pricingService;
private final PaymentService paymentService;
CheckoutFacade(CartService cartService, PricingService pricingService, PaymentService paymentService) {
this.cartService = cartService;
this.pricingService = pricingService;
this.paymentService = paymentService;
}
Receipt checkout(String cartId) {
Cart cart = cartService.load(cartId);
Money total = pricingService.total(cart);
return paymentService.charge(total);
}
}