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
LoyaltyPointsServiceorTicketServicechanges 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
MovieBookingFacadewithout copying the setup code.
2. Structural Breakdown
| Component | Responsibility |
|---|---|
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"
| Feature | Before (Direct Access) | After (Facade Pattern) |
|---|---|---|
| Client Complexity | High; must coordinate multiple objects. | Low; calls one method on one object. |
| Coupling | Tightly coupled to all subsystems. | Loosely coupled via the Facade. |
| Maintainability | Hard; changes ripple through all client code. | Easy; changes are isolated within the Facade. |
| Law of Demeter | Violated; 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.