MVC vs MVP vs MVVM Design Patterns
High-level differences between Model-View-Controller(MVC), Model-View-Presenter(MVP), and Model-View-ViewModel(MVVM) for Android development.
It looks like I have been using MVP without knowing it. In fact, I thought I was using MVC. I came to know about this MVVM while learning Android. I like MVVM because of the unidirectional data flow, which makes the architecture a lot cleaner.
The diagram below gives you side-by-side comparisons between them.
- Dependencies direction: View → Model, Controller → Model and View
- View knows about Model (e.g. data binding), Controller knows everything, Model knows nothing
- Controller observes UI event from View, writes data to the Model and tells the View what to update
- View retrieves the data from model to display
There are different variations of MVC out there. So what I shared here is based on my understanding which I have tweaked a bit from the original MVC design.
- Dependencies direction: Presenter → Model and View
- Presenter knows everything, View and Model know nothing
- Presenter observes UI event from View, writes data to the Model, read the data from Model and provides data to the View for display
MVP is similar to MVC except the View doesn’t depends on the Model. The Presenter takes care of reading/writting the data and passsing the data to the View.
- Dependencies direction: View → View Model → Model
- View knows about View Model, View Model knows about…