In our app, we follow the MVP pattern, separating the internal data model, from a passive view through a presenter that handles the logic of our application and acts as the conduit between the model and the view.
In the Travel app, we define two sets of protocols.
PresenterProtocol protocol that must be implemented by all Presenter objects and
PresentingViewProtocol must be implemented by the corresponding "view" objects.
PresentingViewProtocol may be optionally extended to support capabilities of specific presenter/view
The app defines the following PresenterProtocols that extend the
BookingPresenterProtocol defines methods to be implemented by the Booking Presenter.
FlightPresenterProtocol defines methods to be implemented by the Flight Presenter.
AirportPresenterProtocol defines methods to be implemented by the Airport Presenter.
HotelPresenterProtocol defines methods to be implemented by the Hotel Presenter.
The app defines the following PresentingViewProtocols that extend the
BookingPresentingViewProtocol defines methods to be implemented by the Booking View
The model provides and stores the internal data.
In our travel app, for simplicity, we use standard data types of
Array to represent the data.
In a real application, one would use a custom object to represent the model.
The app implements the following models.
Booking which represents a flight reservation
Flight which represents airline details
Airport which represents airport name
Hotel which represents hotel details
In addition, the
DatabaseManager.swift is a singleton class that is used to manage the common database operations such as Database Creation/Deletion and Replication.
In the Travel app, the
UIView and the
UIViewController classes represent the "view" in MVP.
It handles user input and forwards requests to the Presenter.
It updates the UI based on response from the Presenter.
The view object holds a weak reference to the corresponding Presenter object that implements the corresponding
The app implements the following ViewControllers.
LoginViewController which represents the login UI
BookmarkedHotelsTableViewController which represents the UI that lists bookmarked hotels
BookingTableViewController which represents the flight reservations UI
FlightListingTableViewController which represents the UI that lists of flight details
FlightSearchViewController which represents flight search UI
HotelsTableViewController which represents the UI that lists hotels
HotelDetailViewController which represents the UI that lists hotel details
In addition, there are custom UITableViewCells.
The Presenter acts as the intermediary between the View and the Model.
It holds a weak reference to the corresponding view object that implements appropriate
The app implements the following Presenters.
BookingPresenter which implements the
FlightPresenter which implements the
AirportPresenter which implements the
HotelPresenter which implements the
In addition, there are some simple custom UI widgets like custom UITableViewCells