How to use MVP in your own projects

How to use MVP in your own projects

The official wrote us some MVP sample projects, using different concepts and tools to implement the same Todo project.

Github address

Although before the official launch of this set of MVP open source use cases, there are also many excellent open source projects on the Internet that teach you how to use the MVP model. If you haven’t read it before, there is actually another advantage. Just follow the official As soon as I started, other similar projects were misfired). I took a look at the official todo-mvp, which is a bit simpler and clearer than what I did before, and the test cases are also written more complete, so you can intuitively experience the benefits of MVP in this regard.

Benefits and problems of MVP

When you understand the MVP model, its benefits are obvious:

  1. The UI layer is separated from the logic layer. The UI layer does not involve business logic code, and changes to a certain layer do not need to modify the code everywhere;
  2. Testing is very convenient, you can directly call the Presenter layer to write test styles (you can use the Junit framework);
  3. The last is maintainability and scalability. The responsibilities of each category of MVP are very clear and single. Later expansion and maintenance will be easier.

Of course, the disadvantages are also obvious. First of all, the code classes are increased. You may have to write the implementation of the Presenter and Model layers for a small function. In the past, you added these to the View layer in one go. At the same time, some MVP mode training is needed for new project personnel so that they will not write code that destroys the existing mode.


 

Guess you like

Origin blog.csdn.net/qq_36355271/article/details/90903828