Model–view–controller is both an architectural pattern and a design pattern, depending on where it is used. we can essentially break dow it into there major components from its analogy
- M - Model - your business entities / data
- V - View - your UI
- C - Controller - Implemetation of your business use case.
Controller will be ignorant about View, so that that a View can switch Controllers as well as single controller can be used by multiple Views . One of the disadvantages of MVC is that it’s difficult to unit test. Controller manipulates the data but how about asserting those changes from a view perspective. For instance on click of a button you raise an event to controller, and controller modifies the value in model. This value modification changes the font size / color in View.
M-V-P
- M - Model - your business entities / data
- V - View - your UI
- P- Presenter
Over here we replace Controller with Presenter (one which presents the changes done in model back to view). The main difference between both is that Presenter refers back to the view while Controller doesn’t. Normal pattern found here is to create an interfaceof the View (in terms of properties / events) & Presenter refers to it. Presenter here hence takes the responsibility of not only manipulating model but also updating the view.
M-V-VM
- M - Model - your business entities / data
- V - View - your UI
- VM- View Model
Model–View-ViewModel talks of creating a new model (in addition to your domain model). This model normally adds additonal properties from the prespective of View . For instance if View had a property IsChecked and Presenter was setting in classic MVP, in MVVM Presenter will have that IsChecked Property which View will sync up with . So now a Presenter becomes more like a combo of – View Properties & Model properties which would be synchronized with View. So why not rename Presenter to ViewModel? Do that and you get MVVM. MVVM is attractive for platforms which support bi-directional binding with less effort.