Skip to content

(MVP) Model View Presenter

Devrath edited this page May 29, 2021 · 15 revisions

Improvement from MVC to a better Architecture

To overcome the drawbacks of MVC controller overloading with the business logic. Modifications were done to segregate it to a better representation of architecture called Model-View-Presenter.

MVP block diagram

  • Different people use different variations of the MVP pattern.
  • Common and the most popular type of MVP pattern is by using a contract between the view and the presenter
  • The contract is an interface between the view and the presenter
  • The view calls a method to initiate an action in the presenter, the action can be to fetch the data from the model.
  • Finally once the data is retrieved from the model the presenter notifies the view via the callback from the contract.

MVP + Repository Pattern block diagram

  • A repository is used to manage the data from API and loacal database.
  • We condider Model = Repository + API + Local Database

Using the android architecture component in MVP?

  • Why not - of course, yes.
  • Instead of the contract that exists between view and presenter, We can use a LiveData

Clone this wiki locally