Model-View-Controller
MVC is a pattern for the architecture of a software application. It separate the application logic into three separate parts, promoting modularity and ease of collaboration and reuse. It also makes applications more flexible and welcoming to iterations.It separates an application into the following components:
- Models for handling data and business logic
- Controllers for handling the user interface and application
- Views for handling graphical user interface objects and presentation
To make this a little more clear, let's imagine a simple shopping list app. All we want is a list of the name, quantity and price of each item we need to buy this week. Below we'll describe how we could implement some of this functionality using MVC.
Model-View-Presenter
- The model is the data that will be displayed in the view (user interface).
- The view is an interface that displays data (the model) and routes user commands (events) to the Presenter to act upon that data. The view usually has a reference to its Presenter.
- The Presenter is the “middle-man” (played by the controller in MVC) and has references to both, view and model. Please note that the word “Model” is misleading. It should rather be business logic that retrieves or manipulates a Model. For instance: If you have a database storing User in a database table and your View wants to display a list of users, then the Presenter would have a reference to your database business logic (like a DAO) from where the Presenter will query a list of Users.
If you want to see a sample with simple implementation please check
this GitHub post
A concrete workflow of querying and displaying a list of users from a database could work like this:
What is the difference between MVC and MVP patterns?
MVC Pattern
MVP Pattern
View is more loosely coupled to the model. The presenter is responsible for binding the model to the view.
Easier to unit test because interaction with the view is through an interface
Usually view to presenter map one to one. Complex views may have multi presenters.