Code for the Movie Ticket Booking System
Write the object-oriented code to implement the design of the movie ticket booking problem.
We’ve gone over different aspects of the movie ticket booking system and observed the attributes attached to the problem using various UML diagrams. Let’s explore the more practical side of things, where we will work on implementing the movie ticket booking system using multiple languages. This is usually the last step in an object-oriented design interview process.
We have chosen the following languages to write the skeleton code of the different classes present in the movie ticket booking system:
Java
C#
Python
C++
JavaScript
Movie ticket booking system#
In this section, we will provide the skeleton code of the classes designed in the class diagram lesson.
Note: For simplicity, we are not defining getter and setter functions. The reader can assume that all class attributes are private and accessed through their respective public getter methods and modified only through their public method functions.
Enumerations#
The following code provides the definition of the various enumerations used in the movie ticket booking system:
Note: JavaScript does not support enumerations, so we will be using the
Object.freeze()method as an alternative that freezes an object and prevents further modifications.
Actors#
This section contains the different people that will interact with our movie ticket systems, such as a Customer, Admins, and TicketAgents. All of these classes will inherit the properties of the Person class. The definition of these classes is given below:
Seat #
The Seat will be an abstract class, which serves as a parent for three different types of seats: Platinum, Gold, and Silver. The definition of the Seat and its child classes is given below:
Movie, showtime, and movie ticket #
Next, we will explore the ShowTime, Movie, and MovieTicket classes that provide the details of the movie to the customer. The definition of these classes is given below:
City, cinema, and hall #
This section contains classes like Hall, Cinema, and City that make up the infrastructure of our movie ticket system. The definition of these classes is given below:
Payment #
The Payment class is another abstract class, with the Cash and CreditCard classes as its child. This takes the PaymentStatus enum to keep track of the payment status. The definition of this class is given below:
Notification #
The Notification class is an abstract class that is responsible for sending notifications via email or phone/SMS after actions performed by either the admin and/or customer. Its definition is given below:
Booking #
The Booking class is the main class of our movie ticket booking system and will display the information relating to a particular customer's booking. The definition of this class is given below:
Search and catalog#
The Catalog class contains the movie information and implements the Search interface class to enable the search functionality based on the given criteria (title, language, genre, and release date). The definition of these two classes is given below:
Wrapping up#
We've explored the complete design of a movie ticket booking system in this chapter. We've looked at how a basic movie ticket booking system can be visualized using various UML diagrams and designed using object-oriented principles and design patterns.
Activity Diagram for the Movie Ticket Booking System
Getting Ready: The Car Rental System