A typical MVP application might have a View method such as:

void setDisplayItems(List<DisplayItem> items);

Should the Presenter sort the list of items or is that a task for the view?

I feel this might be a task for the View, for two reasons:

  1. If it were a task for the Presenter, then methods such as:

    void addDisplayItem(DisplayItem item);

    won't work, as the Presenter can't insert the item at the correct place.

  2. The View can offer different sorting options, based on user selections.

However, I also can't shake the feeling that this is too much "thinking" for the View to be doing. Can anyone comment on the correct choice for MVP?

I should note that I typically produce Swing-based Java applications (in case that allows for more specific answers).

  • I wonder why you also didn't ask, should the sorting be done in the Model? – Blundell Feb 18 '16 at 10:16

The correct answer is (drum roll please) it depends. Are you using a UI framework that supports sorting natively? Are you sorting over a large sequence that would be best performed as a database operation? Does your UI framework support sorting through the database (e.g. IQueryable support in many .NET UI toolkits).

There are multiple approaches to MVP. You have the Passive View in which the Presenter has deep knowledge of the view via an Interface, there's the supervising controller in which the presenter handles complex view logic and the rest is left to the view (so again if your view objects can handle sorting, let them do it if it's not an expensive operation), finally is the Presentation Model which is pretty much equivalent to MVVM in which the Presenter exposes behavior as properties and the View reacts to those properties.


I would put logic like this in the Presenter. One of the important jobs of the Presenter is to put the data into the correct form for your View. This will make it easier for you to swap out views in the future.

In general, you should try to avoid putting a lot, if any, logic in your View. The only thing in your view should be visual display code and basic code for displaying data as prepared by the presenter.

  • Thanks for the response. How would you approach the insertion of data into a list? – Duncan Jones Mar 26 '13 at 15:53
  • I'm not sure of the details, but I would build the list in a presenter method, and the view could call that method in the presenter. The basic form of communication between the two would be a sorted list. – Oleksi Mar 26 '13 at 16:17

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.