Android MVP: is it just an excuse for testing?

Honestly, I can't get around all these MVPs and similar things regarding Android: what is its essence?

So far, the only practical reason that I see the use of MVP in Android is to "extract" pieces of code that can be tested from wireframe classes (for example, "Activities", "Services", "Snippets"), which would otherwise be difficult (or impossible) to test.

This is good, but in this way actions (and other infrastructure classes) ultimately delegate work to the facilitator when possible (i.e., when working with the agnostic code of the framework) and work directly when not. Because of this, Hosts end up looking kinda weird, having methods that reflect the Activity lifecycles (onStart, onResume, clickListeners ...). I wonder if this is the smell of code?

In addition to this, I see a ton of libraries / templates for creating MVP applications for Android, but I honestly don’t see their real benefits: what is the disadvantage that each activity creates and manages its own host manually? I do not see any benefit in unleashing the Activity and the Presenter from each other, since the moderator is simply “extracting” some code from the Activity, it will be closely connected with it by definition, and it sounds great to me, as long as the moderator contains only strict presentation logic (the rest of the business logic goes into special classes that do not know anything about the View / Presenter duet).

I feel a little lost in this topic, and I would like other opinions on this issue to get a great perspective.

+5
source share
2 answers

Yes, of course, you can make a presentation logic platform for you - an agnostic for testing, but MVP also helps to change runtime behavior by changing speakers. The presentation interface should have a bit of more abstract methods (not “hide the X button”, describing, say, the display of a data set). By decoupling the UI logic from a structure-dependent implementation, we can use different views to change the user interface or Presenter to change the logic at runtime. View - Presenter is also a gasket, making it difficult to write spaghetti code

0
source

From a long-term point of view, your code should be feasible and easy to repair, no one wants to spend extra time refactoring the code. No, when we start our project, we have to take care of the right templates.

Speaking of MVP, it provides you with a presenter level that can be easily checked, and there is no link to it, so you can easily run junit test cases, otherwise you will have to use other test UI examples.

you can reuse the same presenter anywhere, because it contains only business logic

So my suggestion is that you should go ahead with MVP if you don't want to face a future code problem

0
source

Source: https://habr.com/ru/post/1259959/


All Articles