This project is read-only.

Model-View-ViewModel (MVVM) in a Nutshell

Topics: General - public
Apr 1, 2013 at 4:23 PM
It represents all the business logic. It does all the heavy lifting for us. It should be capable to be used with any View (like our Model could be used without adding a single line of code to it in Console application, Win Forms, WPF Forms, ASPX,...). Model should not know about View and ViewModel.

Is representation of the Model to the user, where he/she can see and interact (in any allowed way) with the data from Model. Like mentioned, View could be Form, Console app, web page,.... View should only know about ViewModel, and nothing else.

Is "Model of the View". Its role in MVVM is to pass View's demands to the Model, and notify any listener about changes. ViewModel should only know about Model. View is glued to the ViewModel with bindings, and notified about changes via events in ViewModel (INotifyPropertyChanged interface implementation, ObservableCollection<T>,...).

Ideally, there is no code-behind in View. View should reference only ViewModel, and ViewModel should reference only Model. Why using such "complicated" software architectural pattern? Because it allows us to test each and every feature in Model and ViewModel, without the View. You can pass any possible value to any member of the Model and/or ViewModel, and see immediate result. Imagine doing it through UI, entering once valid data, then all sorts of invalid data possible, and doing it for every possible thing in UI. Later, after some code change, you'd do the same process again.... No, thanks! And thanks for the MVVM, and TDD (BDD)!