MVC
Model-View-Controller is a design pattern to develop user interface in three interconnected components.
Keep in mind that MVC is not a layered architecture (where each layer can communicate only with the one above or under).
Component
Model
- Describe data state, structure and behaviour
- Handle data access and modification
- Independent from the View and Controller
- Notify the View of changes (observer)
View
- Presentation layer: display the data to the end-user
- Requests update from the Model
- Send user's actions to the Controller
Controller
- Connects end-users to the application
- Handle inputs and requests, converts it to commands
- Update the Model according to user's actions
- Chose the View to respond with
- Can handle several Views.
- Dependent of View and Model
Variants and alternatives
MVP
In Model-View-Presenter, a Presenter is the bridge between the View and the Model.
- Presenter can handle only one View (in contrast with a Controller)
- Presenter listen to both View and Model
- Views must implement an interface to interact with its Presenter
MVVM
In Model-View-ViewModel, a ViewModel bind data between View and Model, instead of using an event-listener system. It is easier to implement and test, but it can lead to code complexity and can be memory-costy.