MVP - What is where?

1

I have a question about MVP. In my studies, I understood that in M = Model everything that has to do with business rules and data manipulation codes related to the business, access to a bank, adapters, etc. In P = Presenter is the presentation, or the interaction between the Model and the View to manipulate, chewing what should be shown. And the View is the preview!

But on Android we have for example native android methods like the onRequestPermissionsResult, OnClickListener listenerTvAddDetalhesRotulo, onActivityResult. Would these items be in the presentation or template?

Or because they are native items of the android I left like this in the same activity?

    
asked by anonymous 28.03.2017 / 23:30

1 answer

1

The model is responsible for the data that will be displayed in the user interface. We could consider as model, besides the data, any logic of manipulation and access of this data.

The view , usually implemented by a Activity (can also be a Fragment or any UI element, depending on the structure of your application), will contain a reference to the presenter . presenter can be created by Activity or provided via dependency injection. The sole responsibility of View is to call methods in Presenter every time the user interacts with it.

Presenter acts as an intermediary between view and model . It removes the model data and returns to the view . But, unlike typical MVC, it also decides what happens when the user interacts with the view .

These definitions were taken from the article by Antonio Leiva .

For methods onRequestPermissionsResult , OnClickListener , onActivityResult ; should be kept in their respective activities or fragments, being part of view in relation to MVP, which are also found in Android's own classes. The listenerTvAddDetalhesRotulo method, which you probably invented, depending on the context, can enter the presenter or model .

If you are interested in good practices when it comes to Android, I recommend reading Best practices in Android development .

    
29.03.2017 / 00:10