Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android MVP - Which model to present to view

Tags:

android

mvp

realm

I am using the MVP design pattern.. The models which I am presenting to my view are currently POJOS that are models for my local Realm database. That being said, they have annotated members relevant to the database. Would it be better to use the presenter to map the DB models returned from the interactor to models that only contain data which the view should utilize (Have a seperate model POJO for my view)? Or is it fine practice to hand the view my db models?

Thanks.

like image 970
Daniel Christopher Avatar asked Oct 30 '22 04:10

Daniel Christopher


1 Answers

The question you have to ask is

If I removed Realm from my app would I have to make changes to my view if I use these entity classes

If the answer is no then I see no problem with using those entities to pass to your view. If however they are tied to Realm in such a way that you would have to change the view then this would break the decoupled idea of MVP.

I personally quite often make a ViewModel anyway. The reason being is I want to minimise the number of separate calls between my Presenter and my View. Ideally your view should be as close as possible to having the methods:

setLoadingUi();
setContentUi(ViewModel model);
setEmptyUi();
setErrorUi();

Whilst this isn't always possible if you have various view calls such as setConfirmButtonText that ties your Presenter into knowing too much about your View. What happens when you change the button for a swipe...your Presenter would need to change as well as your View.

Hope this helps!

like image 160
Jahnold Avatar answered Nov 08 '22 14:11

Jahnold