Skip to content
This repository was archived by the owner on Nov 27, 2024. It is now read-only.
Andreas Niedermair edited this page Dec 23, 2016 · 25 revisions

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:

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.

Model-view-controller (MVC)

   .-""""-.         .-""""-.         .-""""-.         .-""""-.         .-""""-.   
 .`        `.     .`        `.     .`        `.     .`        `.     .`        `. 
/            \   /            \   /            \   /            \   /            \
;    GUI     ;-->; Controller ;-->;    Model   ;-->;    View    ;-->;    GUI     ;
\            /   \            /   \            /   \            /   \            /
 '.        .'     '.        .'     '.        .'     '.        .'     '.        .' 
   '------'         '------'         '------'         '------'         '------'   

(copied and translated from http://userpage.fu-berlin.de/~ram/pub/pub_jf47ht81Ht/mvc)

Model-view-viewmodel (MVVM)

   .-""""-.         .-""""-.         .-""""-.         .-""""-.         .-""""-.   
 .`        `.     .`        `.     .`        `.     .`        `.     .`        `. 
/            \   /            \   /            \   /            \   /            \
;    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.

Model-view-viewmodel-controller (MVVMC)

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   ;         
                 \            /         
                  '.        .'          
                    '------'            

"MVVM w/ Controller"

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.

So, why is "MVVM w/ Controller" not really MVVMC?

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.

TL;DR

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   ;         |
                                        |          \            /         |
                                        |           '.        .'          |
                                        |             '------'            |
                                        |                                 |
                                        '---------------------------------'