7

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?

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.

  • 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. – user4057066 Oct 31 '14 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. – BЈовић Oct 31 '14 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. – user4057066 Nov 3 '14 at 5:06
  • 1
    @user4057066 Hard to answer, without seeing details (code and design). I would extract the common part – BЈовић Nov 3 '14 at 7:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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