In the MVP architecture, how should the Model layer get its data

androiddata structuresmvp

I am new to high-level (Android / Java) application development and I learned of the MVP (Model, View, Presenter) architecture. But it's not clear what the role and design of the Model layer is supposed to be.

Most tutorials and blogs about MVP directly discuss and show examples of the View and Presenter layers, but either skip or only lightly touch on the Model.

Should an API that passes data via events have the callback handled in the Model or the Presenter, and in this case is it the Presenter's job to notify the Model of new data from the API or the Model's job to notify the Presenter that it's state changed? Who's responsibility is it to handle updates to the Model not originating from the View?

I understand the Model should store the data to be displayed by the View, and it's responsible for how the data is handled. But, how should it get its data that doesn't specifically come from the View?

Best Answer

The MVP pattern basically separates the model, from a view through a presenter. Here, the presenter listens for any user interaction through the view. The presenter then fetches the relevant info from a particular service (maybe an API). After that the presenter updates both the view as well as the data. As a result you can see that the model and the view layers are completely isolated from each other.

Below you can see a diagrammatic illustration:

enter image description here

Related Topic