What is MVP architecture in Android ?

  • MVP is a design pattern for developers to write their code in a more readable, maintainable, and scalable manner.
  • In MVP, our code is divided into three parts named Model, View, and Presenter rather than placing the whole code in one activity.
    • Model – The model handles the data part of our application.
    • Presenter – It acts as a bridge that connects a Model and a View.
    • View – This is responsible for laying out views with the relevant data as instructed by the Presenter.
Model View Presenter

Model

  • Everything which is related with data is a part of the Model. The Model contains a data provider and the code which fetches and updates the data.
  • This part of MVP updates the database or communicates with a web server.

Presenter

  • The Presenter contains the application’s business logic and when an operation is performed or data is changed then it will notify the View that it needs to update.

View

  • The View part of MVP contains the visual parts of our application, like showing messages, and also handles visibility.
  • View contains only that part of the code which is related to UI and it does not contain any logic related to the displayed data. The View is controlled by the Presenter.

Android MVP Architecture

  • The diagram below depicts a basic MVP structure.
 Tell me honestly about the run Android MVP Architecture
  • ActivityFragment and a CustomView act as the View part of the application.
  • The Presenter is responsible for listening to user interactions (on the View) and model updates (databaseAPIs) as well as updating the Model and the View.
  • Generally, a View and Presenter are in a one to one relationship. One Presenter class manages one View at a time.
  • Interfaces need to be defined and implemented to communicate between View-Presenter and Presenter-Model.
  • The Presenter is responsible for handling all the background tasks. Android SDK classes must be avoided in the presenter classes.
  • The View and Model classes can’t have a reference of one another.

Categorized in:

Tagged in:

, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,