4

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?

gnat
20.5k29 gold badges117 silver badges308 bronze badges
asked Aug 10, 2017 at 20:57
3
  • 3
    Generally 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. Commented 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? Commented Aug 10, 2017 at 21:36
  • OOP is one way of creating a Model. See also medium.com/@cervonefrancesco/…. Commented Aug 10, 2017 at 22:05

1 Answer 1

3

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

answered Sep 29, 2017 at 12:53
1
  • Would the model ever be connected to the Service as opposed to the Presenter connecting to the Service and updating the Model? Commented May 31, 2018 at 15:41

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.