MVP Architecture
Overview
The Model-View-Presenter pattern
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.

Protocols
In the Travel app, we define two sets of protocols.
The PresenterProtocol
protocol that must be implemented by all Presenter objects and PresentingViewProtocol
must be implemented by the corresponding "view" objects.
The PresenterProtocol
and PresentingViewProtocol
may be optionally extended to support capabilities of specific presenter/view
The app defines the following PresenterProtocols that extend the PresenterProtocol
protocol.
-
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 PresentingViewProtocol
protocol.
-
BookingPresentingViewProtocol defines methods to be implemented by the Booking View
Model
The model provides and stores the internal data.
In our travel app, for simplicity, we use standard data types of Dictionary
and 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.
View
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 PresenterProtocol
.
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.
Presenter
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 PresentingViewProtocol
.
The app implements the following Presenters.
-
BookingPresenter which implements the
BookingPresenterProtocol
-
FlightPresenter which implements the
FlightPresenterProtocol
-
AirportPresenter which implements the
AirportPresenterProtocol
-
HotelPresenter which implements the
HotelPresenterProtocol
In addition, there are some simple custom UI widgets like custom UITableViewCells