Designing MovieBooking

The application contains two main packages: moviebooking.ui, which contains all the GUI related classes and moviebooking.moviedb, which contains the business logic. This tutorial does not focus much on the movie database itself and only contains a short review of this package.

The application provides the user with the ability to contact the database and retrieve the list of available movies. Since this procedure may take a while, a splash screen is displayed at startup informing about the progress of the connection. The list of movies is displayed on the screen so that the user can see what is available and retrieve a short description of each movie.

Upon requesting to book seats for a movie, a form is displayed so that the user can enter the needed data, such as names and day and time of the showing. Additionally, the user can select a specific seat in the theater using a diagram of the seating.

Once all the information is available, the booking request is sent to the database and the response is displayed to the user, who can go and book an another movie. At any time the user can select to close the application.

All these tasks are straightforward to implement and are discussed under the description of each class.

MovieDB

The movie database package contains the business logic methods used to query and manipulate the movie database. The example is designed with the idea of a remote database contacted over the network so that it can use the most current data. Hence, some of the methods are to be executed asynchronously.

In practice, for this example, we just use a local list of movies retrieved from a properties file. We attempt anyway to provide an accurate simulation so some actions are executed in a separate thread and the results are delivered asynchronously.

The database classes are contained in the moviebooking.moviedb package. Its content is shown in the UML diagram below.

Figure 38: Package moviebooking.moviedb

The MovieDB class abstracts the database and takes care of operations requiring accessing the database. The movie database contains a set of Movie objects created from the data contained in a text file. Each Movie object contains a set of Showings, which contain each particular presentation of the movie and the distribution of the seats. The seating is contained in an array of booleans with the true value meaning that the seat is already occupied.

All this data is loaded or generated in a separate thread and artificial pauses are included to make the behavior more realistic. The date and time of the showings is generated at runtime so that the date is based on the current date. The distribution of seats is also built randomly trying to get one third of the seats occupied.

The results of asynchronous operations are relayed to an interested observer that has to implement the MovieDBListener interface. This interface contains the handleEvent method, which is called when an interesting event happens. The handleEvent method takes a MovieDBEvent object which contains the event type and some extra data if needed.

The actual booking of a movie is simulated in the sendBookingRequest method. This method spawns a separate thread and asynchronously deliver a Booking object containing the booking information.