-
Notifications
You must be signed in to change notification settings - Fork 0
MVVMC
MVVMC is a combination of Model-view-controller (MVC) and Model-view-viewmodel (MVVM), to get the best of both worlds.
This pattern is not new, there are already some publications available:
- (2010) MVMMC – MVVM Grows A Controller http://trelford.com/blog/post/MVMMC-e28093-MVVM-grows-a-Controller.aspx
- (2010) MVC/MVVM is not an either/or choice. http://stackoverflow.com/a/3540895/57508
- (2010) Maybe it should have been called MVCVM instead? http://stackoverflow.com/a/3511984/57508
- (2012) MVVM is dead, long live MVVMC! http://skimp-blog.blogspot.co.at/2012/02/mvvm-is-dead-long-live-mvvmc.html
- (2012) Silverlight MVCVM – MVVM With Controllers http://blog.hitechmagic.com/?page_id=513
- (2013) A JavaScript MVCVM framework. It's not for you, and you probably wouldn't like it anyway. https://github.com/mysterycommand/palindromejs
- (2014) MVVMC thought experiment http://kev-sharp.blogspot.co.at/2014/05/mvvmc-thought-experiment.html
- (2014) http://softwareengineering.stackexchange.com/questions/254201/why-should-viewmodel-route-actions-to-controller-when-using-the-mvcvm-pattern
- (2016) Sample code from MVVM-C In Practice Talk https://github.com/macdevnet/mvvmc-demo
Yet, a definite definition is to be made 🎉
Disclaimer: There are 10 people with 12 opinions. If you have any issues with the definitions, want to extend the sections, ... please get in contact with me directly.
.-""""-. .-""""-. .-""""-. .-""""-. .-""""-.
.` `. .` `. .` `. .` `. .` `.
/ \ / \ / \ / \ / \
; GUI ;-->; Controller ;-->; Model ;-->; View ;-->; GUI ;
\ / \ / \ / \ / \ /
'. .' '. .' '. .' '. .' '. .'
'------' '------' '------' '------' '------'
(copied and translated from http://userpage.fu-berlin.de/~ram/pub/pub_jf47ht81Ht/mvc)
.-""""-. .-""""-. .-""""-. .-""""-. .-""""-.
.` `. .` `. .` `. .` `. .` `.
/ \ / \ / \ / \ / \
; GUI ;-->; View ;-->; View Model ;++>; View ;-->; GUI ;
\ / \ / \ / \ / \ /
'. .' '. .' '. .' '. .' '. .'
'------' '------' '------' '------' '------'
( \/ /\ )
.-""""-.
.` `.
/ \
; Model ;
\ /
'. .'
'------'
The +++
-line symbolizes an indirect dependency between the View Model
and View
- this is possible, due the implementation of a mediator, ie Data Binding (WPF).
Thanks to this type of dependency one can reuse the View Model
and the Model
for other applications, such as unit tests.
The main motivation for the introduction of a Controller
is to avoid the blending of state and logic in one entity (View Model
) 😋. To make the concrete shape of the state exchangeable, a Controller
is introduced, which can create different Model-view-viewmodel
-triads according to the needs of the input, showing the same data in a different shape.
.-""""-. .-""""-. .-""""-. .-""""-. .-""""-.
.` `. .` `. .` `. .` `. .` `.
/ \ / \ / \ / \ / \
; GUI ;-->; Controller ;-->; View Model ;++>; View ;-->; GUI ;
\ / \ / \ / \ / \ /
'. .' '. .' '. .' '. .' '. .'
'------' '------' '------' '------' '------'
( \/ /\ )
.-""""-.
.` `.
/ \
; Model ;
\ /
'. .'
'------'
This is a special form of MVVMC, which is implemented with Caliburn.Micro.Contrib.Controller
for Caliburn.Micro
.
The reason for such an adaptor-like approach is the fact that WPF is basically based on (or at least strongly influenced by) MVVM, and thanks to this fact, there exist many powerful MVVM frameworks, Caliburn.Micro
being one of them.
There is no possibility for the GUI
to directly communicate with the Controller
, instead we are (ab)using the View
for this.
The original architecture places the View Model
before the Controller
, which also enforces the View Model
holding a Controller
to forward the UI-commands to the Controller
. This felt a bit too vanilla, aka tedious boiler code to be produced en masse.
A proxy is placed between View
and ViewModel
, which redirects the UI-commands to the Controller
and leaves the bindings untouched. This is also the reason for the savage requirements for ViewModel
classes, hence making the injection of the proxy as transparent as possible.
So that the
View Model
becomes a dumb state class. 😏
.-""""-. .-""""-. .-""""-. .-""""-. .-""""-. .-""""-.
.` `. .` `. .` `. .` `. .` `. .` `.
/ \ / \ / \ / \ / \ / \
; GUI ;-->; View ;-->; Proxy ;-->; Controller ;-->; View Model ;++>; View ;
\ / \ / \ / \ / \ / \ /
'. .' '. .' '. .' '. .' '. .' '. .'
'------' '------' '------' '------' '------' '------'
| ( \/ /\ ) ^
| .-""""-. |
| .` `. |
| / \ |
| ; Model ; |
| \ / |
| '. .' |
| '------' |
| |
'---------------------------------'