Design

The MovieBooking MIDlet serves as the front-end of a movie theatre ticket booking system. Since the MIDlet is only intended to serve as an example, some of the code has been implemented to mimic real deployment environments. For example, while the back-end is typically located on a remote server and connections are formed using web services, this MIDlet uses a simulated local database.

The MIDlet contains two main packages:

  • com.nokia.example.moviebooking.ui contains UI-related classes.

  • com.nokia.example.moviebooking.moviedb contains the business logic.

    This example does not focus on the movie database itself, and only contains a short review of the com.nokia.example.moviebooking.moviedb package.

The MIDlet provides the user with the ability to contact the database and retrieve a list of available movies. Since the retrieval can take time, the MIDlet displays a splash screen at startup informing the user about the progress of the retrieval. After the movie list has been retrieved, the MIDlet displays it on the screen so that the user can see both what is available and read a short description of each movie.

Figure: Displaying a list of available movies

When the user wants to book seats for a movie, a form is displayed where the user can enter the needed data, such as names and the day and time of the showing. Additionally, the user can select a specific seat in the theater using a seating diagram. Once all the information is available, the MIDlet sends the booking request to the database and displays the response to the user. The user can close the application at any time.

Movie database

The com.nokia.example.moviebooking.moviedb package contains the business logic methods used to query and manipulate the movie database. Since the MIDlet is designed with a remote database in mind, one that is contacted over the network to access the most current data, some of the methods are executed asynchronously. However, in practice, the MIDlet uses a local list of movies retrieved from a properties file. To provide an accurate simulation, however, some actions are executed in a separate thread and the results are delivered asynchronously.

The following figure shows the UML diagram for the database classes contained in the com.nokia.example.moviebooking.moviedb package:

Figure: Database class diagram

The MovieDB class abstracts the database and takes care of the operations requiring database access. 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 Boolean values with the true value meaning that the seat is already occupied.

All the 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. The 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 additional data, as needed.

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

Implementation

For information about implementing the MIDlet, see section Implementation.