8

I am using MVP for creating an android application, which takes data from server and sets to activity.

I am forced to create one presenter for each view.
Each view is unique because each view has different textviews/labels.
The presenter will read values from model and call setter method for each control in view.
For second view, I will need different presenter, as I need to call some other setter methods on the view interface.

This means view - presenter will have one to one relationship.
Is it ok for view - presenter to have one to one relation in MVP or my approach is not correct?

EDIT: I will be using one presenter for each view because I have to. Because each presenter will implement the functionality unique for each view.

However that poses reusability problem. The presenters have a lot of common code. eg calling helper to load data from URL etc. So I am planning to use either the abstract factory pattern or the strategy pattern. The problem with abstract factory pattern is , if tomorrow my presenter need to extend another class, it cannot be done because i m coding in java. So is it advisable to use abstract factory pattern in java , for the presenter group?

1 Answer 1

8

Yes, it is fine.

Applying MVP design pattern means having MVP triplets (model-presenter-view) per every (even a bit complex) item to display. The logic goes to the model, and the presenter is there just to glue things.

4
  • Ok. Thanks. One more doubt, the activesync, documentparser and database queries shall be called from the presenter or the model? As per my understanding, the database queries will be called from the model. But document parser will be called from presenter. Oct 31, 2014 at 4:39
  • @user4057066 Presenter is just a glue between view and model. DB questies are for the view. The model contains the logic (which you can unit test). The view is not unit tested. The presenter is also unit tested. Oct 31, 2014 at 6:26
  • Ok. the 2 presenters have many common functinalties. So shall i stick to using one presenter with some methods different based on view object. Shall I use the strategy pattern with both presenters instantiating a 3rd presenter based on the view object. Shall there be helper class with the common menthods? Or any better way to do it in MVP. Nov 3, 2014 at 5:06
  • 1
    @user4057066 Hard to answer, without seeing details (code and design). I would extract the common part Nov 3, 2014 at 7:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.