Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between controller in MVC pattern and presenter in MVP pattern?

What is the difference between controller in MVC pattern and presenter in MVP pattern? Can you provide links for understanding the Merits and usage scenario for both of them?

like image 864
Sulla Avatar asked Jan 19 '11 09:01

Sulla


People also ask

How does MVP differ from the MVC model view controller pattern?

MVP pattern overcomes the challenges of MVC and provides an easy way to structure the project codes. The reason why MVP is widely accepted is that it provides modularity, testability, and a more clean and maintainable codebase.

What does the presenter do in MVP?

The Presenter is responsible to act as the middle man between View and Model. It retrieves data from the Model and returns it formatted to the View. But unlike the typical MVC, it also decides what happens when you interact with the View.

What are the similarities between MVC and MVP design patterns?

The MVP pattern is similar to the MVC pattern. It is derived from MVC pattern, wherein the controller is replaced by the presenter. This pattern divides an application into three major aspects: Model, View, and Presenter. The Model represents a set of classes that describes the business logic and data.

What's the advantage of MVP compared to MVC?

The Model View Presenter (MVP) Pattern The presenter replaces the Controller (in MVC) in the MVP design pattern. The MVP pattern allows for easier mocking of the view and more efficient unit testing of applications. In the MVP pattern, the presenter manipulates the model while simultaneously updating the view.


2 Answers

In MVP the Presenter assumes the functionality of the "middle-man" (played by the Application Controller in MVC). Additionally, the View is responsible for handling the UI events (like mouseDown, keyDown, etc), which used to be the Controller's job. Eventually, the Model becomes strictly a Domain Model.

Says Wikipedia.

Here is a more detailed explanation on the differences between the two.

See also Martin Fowler's Retirement note for Model View Presenter.

like image 141
Péter Török Avatar answered Jan 02 '23 05:01

Péter Török


In MVC, the view is updated only by the model (by listening to its events). It is never updated by the controller. This is problematic when you need to format model data for the view, hence the need for MVP.

In MVP-Passive View, the view is updated only by presenter (presenter sets view properties). The presenter listens to events on the model [modifying the data if required] prior to updating the view.

In MVP-Supervising Controller, the view is updated by either the model or the presenter. If no formatting is required, the view updates itself via the model. If formatting is required, it updates itself via the presenter.

like image 40
Neil McGuigan Avatar answered Jan 02 '23 06:01

Neil McGuigan