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?
-
3Generally speaking, MV* architectures don't have much to say about how your Model is designed. The purpose of such architectures is to abstract UI and routing concerns away from your Model; the architecture of your Model is mostly left up to you. That's why you don't see the Model discussed in detail. If you want to know in detail how to construct a Model, have a look at books like Eric Edwards' Domain-Driven Design.Robert Harvey– Robert Harvey08/10/2017 21:04:05Commented Aug 10, 2017 at 21:04
-
@RobertHarvey Thanks for the response. I'm a computer engineering student right now, and I was tasked with making an Android app at my current internship, so I'm a little outside my realm. Based on your response, is my question is more related to OOP than the MVP architecture itself?ForlornGeas– ForlornGeas08/10/2017 21:36:45Commented Aug 10, 2017 at 21:36
-
OOP is one way of creating a Model. See also medium.com/@cervonefrancesco/….Robert Harvey– Robert Harvey08/10/2017 22:05:42Commented Aug 10, 2017 at 22:05
1 Answer 1
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:
-
Would the model ever be connected to the Service as opposed to the Presenter connecting to the Service and updating the Model?GisMofx– GisMofx05/31/2018 15:41:03Commented May 31, 2018 at 15:41