2
votes

I have a question related to MVP design pattern.

I have a View that passes to the presenter all events. The presenter has the bussiness logic and updates the view. The model is just a collection of JPA entities .

The question is, who is responsible for accessing the database and retrieving the model?

My first thought is that this is a presenter responsibility. BUT, imagine that the same business logic is necessary in several pages, for example, verify if a user has permission to access something. In this case, the business logic would appear in several presenter classes, which is not good.

What would be the best implementation?

1

1 Answers

0
votes

It sounds like you're interested in the differences between MVP and MVC. Note that MVP is a newer variation of the classic MVC architecture, with a key difference being who accesses the model (see the differing diagrams in the Wikipedia articles).

In the classic MVC pattern, both the View and Controller access the model, whereas only the Presenter has access in MVP. Also note that in MVP, not all business logic is necessarily located in the Presenter. From Wikipedia, "The degree of logic permitted in the view varies among different implementations... the view... may be the best place to handle a particular interaction or command."

The answer to your second question is, of course, "It depends on what you're implementing." If you think that MVP will result in duplicated logic in the Presenter of your particular application, consider moving some logic to the View, or consider switching to the MVC pattern.