Class Diagram
Purpose of the Class Diagram
The class diagram is the structural blueprint of our Movie Ticket Booking System. It answers:
- What classes exist in the system?
- What attributes and methods does each class have?
- How do the classes relate to each other?
This problem has more classes than the easy or medium problems you've seen — roughly 12-15 types including enums, interfaces, and concrete classes. The key structural insight is the ShowSeat bridge: a physical Seat exists permanently on a screen, but its availability changes per show. ShowSeat links a Seat to a Show and tracks hold/booking status for that specific showing.
We'll derive every class from the requirements defined in the previous tutorial. No class should exist without a requirements-driven justification.
Identifying Classes from Requirements
Using the noun/verb extraction technique from Fundamentals S8, we analyze our requirements:
Key Nouns --> Candidate Classes:
| Requirement | Nouns Found | Candidate Class |
|---|---|---|
| R1: "Movies with title, description, duration, language, genre" | movie, title, genre, language | Movie (entity), Genre (enum), Language (enum) |
| R2: "Multiple theatres, each containing screens" | theatre, screen | Theatre, Screen |
| R3: "A show associates a movie with a screen at a date and time" | show, date, time | Show |
| R4: "Seats categorized by type: Standard, Premium, VIP" | seat, seat type | Seat, SeatType (enum) |
| R5: "Available seats for a given show" | seat availability per show | ShowSeat (bridges Seat and Show) |
| R6: "Temporary hold on seats for a configurable duration" | hold, hold status, timer | ShowSeatStatus (enum) |
| R7: "A booking aggregates seats for a single show" | booking | Booking |
| R8: "Accept payment for a pending booking" | payment | Payment, PaymentStatus (enum) |
| R10: "Booking status: PENDING, CONFIRMED, CANCELLED, EXPIRED" | booking status | BookingStatus (enum) |
| R11: "Pricing based on seat type, showtime, day" | pricing strategy | PricingStrategy (interface) |
| R12: "Notify users of booking changes" | notification | NotificationService (interface) |
| R13: "Search movies, search shows" | search | Methods on service classes |
Key Verbs --> Candidate Methods:
- "search movies by title/genre/language" -->
MovieService.searchMovies() - "view available seats for a show" -->
ShowService.getAvailableSeats(show) - "select seats" (place hold) -->
BookingService.holdSeats(user, show, seats) - "make payment" -->
BookingService.makePayment(booking, paymentDetails) - "cancel booking" -->
BookingService.cancelBooking(booking) - "expire seat holds" -->
BookingService.expireHold(booking) - "calculate ticket price" -->
PricingStrategy.calculatePrice(show, seat) - "schedule shows" -->
ShowService.scheduleShow(movie, screen, dateTime)
This gives us 17 types: 6 enums, 2 interfaces, 8 concrete classes, and 1 service class.
Defining Relationships
Now let's determine how these classes connect and justify each relationship type:
-
Theatre --> Screen (Composition, 1..*) — A theatre physically contains its screens. Screens cannot exist without a theatre — demolishing the theatre destroys all its screens. This is the hallmark of composition: the whole owns the parts. Compare with DP1 where ParkingLot composes Floors.
-
Screen --> Seat (Composition, 1..*) — Seats are physically installed in a screen. A seat at row 5, column 3 is part of that screen's structure. Removing the screen removes its seats. Again, composition.
-
Show --> Movie (Association) — A show references a movie, but the movie exists independently. The same movie can have many shows across different theatres. Deleting a show doesn't delete the movie.
-
Show --> Screen (Association) — A show is scheduled on a screen, but the screen exists independently. Multiple shows run on the same screen on different days.
-
Show --> ShowSeat (Composition, 1..*) — Each show creates its own set of ShowSeat instances. ShowSeats only make sense in the context of their show — "seat 5C for the 7PM show" is meaningless without the show. When a show is removed, its ShowSeats are removed.
-
ShowSeat --> Seat (Association) — A ShowSeat references the physical seat it represents. The physical seat exists permanently on the screen.
-
Booking --> ShowSeat (Association, 1..*) — A booking references one or more ShowSeats. The ShowSeats are not owned by the booking — they continue to exist if the booking is cancelled (their status reverts to AVAILABLE).
-
Booking --> User (Association) — A booking references the user who made it. The user exists independently.
-
Booking --> Payment (Composition, 0..1) — A payment is created as part of the booking workflow. The payment doesn't exist without its booking. If we delete the booking record, the payment goes with it.
-
Booking --> Show (Association) — A booking references which show it's for.
-
BookingService --> PricingStrategy (Association) — The service uses a pricing strategy to compute ticket prices. The strategy is injected and swappable (Strategy Pattern).
-
BookingService --> NotificationService (Association) — The service uses notification to alert users. The notification service is injected.
Why Composition for Theatre --> Screen but Association for Show --> Movie?
Composition means the part cannot exist without the whole. A screen is physically built into a theatre — it has no identity outside of it. But a movie exists in the movie catalog independently of any show. The movie "Inception" exists whether or not any theatre is currently showing it. This lifecycle independence is the hallmark of association.
Build the Class Diagram
Build it below in the lesson's order — the venue structure, then the show model, then the booking workflow, then the service layer — and predict each relationship before it is drawn. Then unfold any class to see its members, or test why a seat's status lives on ShowSeat and not on Seat.

Complete Class Diagram

Key Design Decisions
1. Why ShowSeat instead of tracking availability directly on Seat?
This is the most important design decision. A physical Seat (row 5, column 3, PREMIUM) is a permanent fixture of a screen. But its availability changes per show — seat 5C might be booked for the 3PM show but available for the 7PM show. If we put a status field on Seat, we can only track one show at a time. ShowSeat is the many-to-many bridge: it pairs a Seat with a Show and tracks the per-show status (AVAILABLE, HELD, BOOKED). This is a classic association class pattern. Compare with the Library System (DP9) where BookCopy bridges Book with availability status.
2. Why Composition for Theatre --> Screen but Association for Show --> Movie?
A screen is physically built into a theatre. It has no identity outside of "Screen 3 in PVR Juhu." Removing the theatre removes its screens — this is composition. A movie, on the other hand, exists in the catalog independently. "Inception" exists whether or not any theatre is currently showing it. A show merely references a movie — deleting the show doesn't delete the movie. This lifecycle independence makes it association.
3. Why Composition for Show --> ShowSeat?
"ShowSeat for seat 5C in the 7PM Inception show" only makes sense as part of that show. When the show is removed from the system, all its ShowSeats become meaningless. The ShowSeat has no lifecycle independent of its Show — composition.
4. Why a separate Payment class (not just a status on Booking)?
Payment has its own lifecycle and attributes — transaction ID, payment method, amount, payment timestamp, payment status (PENDING/COMPLETED/FAILED/REFUNDED). Putting all of this on Booking would violate SRP (Fundamentals S6). The Booking is about what was booked; the Payment is about how it was paid. Separating them also enables features like partial refunds and payment retry without modifying the Booking class.
5. Why PricingStrategy as an interface?
Different shows need different pricing — matinee shows get discounts, weekend shows get surcharges, premiere shows get premium rates. Without the Strategy Pattern, we'd need if/else chains inside BookingService: if matinee: apply 20% discount elif weekend: apply 30% surcharge.... Every new pricing model means modifying BookingService — violating Open/Closed (Fundamentals S6). With Strategy, we inject any PricingStrategy at configuration time. BookingService never knows which algorithm runs. This is the same pattern used in the Parking Lot (DP1) for pricing and the Elevator System (DP8) for scheduling.
6. Why does BookingService hold the timeout configuration?
The hold timeout (8 minutes by default) is a system-level policy, not a per-booking decision. BookingService owns this configuration and passes it down when creating holds. This keeps the timeout centralized — changing it in one place affects all new bookings.