MVP pattern

In traditional Android development, we generally use the MVC pattern for development.
Introduction to the traditional MVC pattern:
  1. View: View layer, corresponding to xml file
  2. Controller: Control layer, corresponding to Activity and Fragment layers, for data processing
  3. Model: Entity layer, responsible for obtaining entity data
One of the biggest drawbacks of using the MVC model in Android development is that the ability of xml to be used as a View layer view is too weak, so in general, we use the Controller layer to assist in processing some views. As a result, the Controller not only acts as the control layer, but also undertakes most of the functions of the View layer. The use of the MVC pattern often leads to very complex codes in Activity and Fragment. It is more appropriate to call the MVC pattern adopted in Android the MV pattern.
MVP mode introduction:
  1. View: View layer, corresponding to xml files and Activity/Fragment
  2. Presenter: Logic control layer, holding both View and Model objects
  3. Model: Entity layer, responsible for obtaining entity data
 
The advantages of adopting the MVP model are:
  1. The business logic is extracted to the Presenter layer, and the View layer focuses on UI processing.
  2. Separate view logic and business logic to achieve decoupling.
  3. Improve code readability.
  4. Presenter is abstracted into an interface, which can be unit tested based on how Presenter is implemented.
  5. Strong scalability.
Disadvantages of adopting the MVP model:
  1. The project structure will have a certain impact on the later development and maintenance. It depends on the size of the app.
  2. The amount of code will increase, and how to avoid writing too many duplicate codes with similar functions is a key issue to be dealt with in MVP development.
  3. There is a certain learning cost.
To sum up, the advantages of using the MVP model on Android are: greatly optimizing the maintainability and scalability of the code, while deeply decoupling the code, making the division of labor at each level clearer.
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325020595&siteId=291194637
MVP