Structural Design Pattern · Java

Facade Design Pattern in Java

Provide one simple entry point to a complex subsystem.

What is Facade?

Facade hides the order and details of several service calls. Clients use a small API instead of learning every subsystem class.

Beginner-friendly Java example

The following example shows the central idea of this pattern in a small, practical scenario.

class Inventory { void reserve(String item) { } }
class Payment { void charge(double amount) { } }
class Shipping { void ship(String item) { } }

class OrderFacade {
    private final Inventory inventory = new Inventory();
    private final Payment payment = new Payment();
    private final Shipping shipping = new Shipping();

    void placeOrder(String item, double amount) {
        inventory.reserve(item);
        payment.charge(amount);
        shipping.ship(item);
    }
}

Benefits and trade-offs

Benefits
  • Separates responsibilities clearly.
  • Improves flexibility as the application grows.
  • Encapsulates structural complexity.
Trade-offs
  • Can introduce extra wrapper classes.
  • Choose the pattern only when the complexity is real.

When should you use it?

  • Simplifying a checkout workflow
  • Hiding a library subsystem
  • Providing a stable application API
Key takeawayProvide one simple entry point to a complex subsystem. Start with the smallest structure that solves the coupling or composition problem.