Skip to content

Design Pattern: Facade (Structural)

One simple door in front of a complex subsystem

Builds on Coupling and Cohesion

Stage 3core2 min read

The Facade Pattern Solution

The refactored code uses the Facade Pattern: one higher-level interface in front of a set of subsystem classes. The new MovieBookingFacade hides the inner details of the movie theater logic, so the client has much less to do.


1. Key Improvements

Simplified Interface

  • The Benefit: The client (Main) no longer manages five service objects or remembers the order of the booking steps.
  • The Impact: The multi-step process is now one method call: bookMovieTicket().

Loose Coupling (Dependency Management)

  • The Benefit: The client now depends only on MovieBookingFacade, not on five concrete service classes.
  • The Impact: If a subsystem such as LoyaltyPointsService or TicketService changes inside, the client code is not affected.

Encapsulation of Workflow

  • The Benefit: The facade runs the steps in the correct business order (for example, payment before the ticket).
  • The Impact: Clients cannot call steps in the wrong order or skip a required step such as the notification.

Better Reusability

  • The Benefit: The booking logic is in one place.
  • The Impact: Any other part of the app (a mobile API or a web controller) can reuse MovieBookingFacade without copying the setup code.

2. Structural Breakdown

ComponentResponsibility
Facade (MovieBookingFacade)Knows which subsystem class handles each part of a request and passes the work to it (delegates).
Subsystems (Payment, Seat, etc.)Each does one specific job. They do not know the facade exists and work on their own.
Client (Main)Talks only to the facade to get a high-level task done.

3. Comparison of "Before" vs "After"

FeatureBefore (Direct Access)After (Facade Pattern)
Client ComplexityHigh; must coordinate multiple objects.Low; calls one method on one object.
CouplingTightly coupled to all subsystems.Loosely coupled via the Facade.
MaintainabilityHard; changes ripple through all client code.Easy; changes are isolated within the Facade.
Law of DemeterViolated; client talks to "strangers".Respected; client talks only to its immediate friend.

4. Summary of the "Entry Point"

The Facade Pattern is like a Help Desk. You do not walk through every department in a building. You go to one desk, and the clerk deals with all the departments for you.

In this topic

After code1 file

After/Main.java125 linesGitHub
package DesignPatterns.StructuralPatterns.FacadeDesignPattern.After;/** * SUBSYSTEM CLASSES * These classes represent the internal complexities of the system. * They are still accessible but the client no longer needs to manage them directly. */class PaymentService {    public void makePayment(String accountId, double amount) {        System.out.println(            "Payment of ₹" + amount + " successful for account " + accountId        );    }}class SeatReservationService {    public void reserveSeat(String movieId, String seatNumber) {        System.out.println(            "Seat " + seatNumber + " reserved for movie " + movieId        );    }}class NotificationService {    public void sendBookingConfirmation(String userEmail) {        System.out.println("Booking confirmation sent to " + userEmail);    }}class LoyaltyPointsService {    public void addPoints(String accountId, int points) {        System.out.println(            points + " loyalty points added to account " + accountId        );    }}class TicketService {    public void generateTicket(String movieId, String seatNumber) {        System.out.println(            "Ticket generated for movie " + movieId + ", Seat: " + seatNumber        );    }}/** * THE FACADE * This class provides a simplified, higher-level interface to a set of * interfaces in the subsystem. It delegates client requests to appropriate objects. */class MovieBookingFacade {    private PaymentService paymentService;    private SeatReservationService seatReservationService;    private NotificationService notificationService;    private LoyaltyPointsService loyaltyPointsService;    private TicketService ticketService;    // Encapsulation: The Facade manages the lifecycles of the internal services.    public MovieBookingFacade() {        this.paymentService = new PaymentService();        this.seatReservationService = new SeatReservationService();        this.notificationService = new NotificationService();        this.loyaltyPointsService = new LoyaltyPointsService();        this.ticketService = new TicketService();    }    /**     * UNIFIED INTERFACE     * This method orchestrates the complex workflow of booking a ticket.     * If the order of operations changes, we only update it here.     */    public void bookMovieTicket(        String accountId,        String movieId,        String seatNumber,        String userEmail,        double amount    ) {        // Step 1: Financial Transaction        paymentService.makePayment(accountId, amount);        // Step 2: Resource Allocation        seatReservationService.reserveSeat(movieId, seatNumber);        // Step 3: Fulfillment        ticketService.generateTicket(movieId, seatNumber);        // Step 4: Engagement/Rewards        loyaltyPointsService.addPoints(accountId, 50);        // Step 5: Communication        notificationService.sendBookingConfirmation(userEmail);        System.out.println("Movie ticket booking completed successfully!");    }}/** * THE CLIENT * Now follows the "Principle of Least Knowledge." * It only knows about the Facade, not the individual subsystems. */class Main {    public static void main(String[] args) {        // High-level intent: "I want to book a ticket"        MovieBookingFacade movieBookingFacade = new MovieBookingFacade();        // One call replaces the 10-line ritual from the "Before" code.        movieBookingFacade.bookMovieTicket(            "user123",            "movie456",            "A10",            "user@example.com",            500        );    }}

Done with this topic?

How well do you know it?

PreviousDesign Pattern: Decorator (Structural)