MVVM is an architecture pattern where we divide the project in to three logical layers and every layer has its own responsibility.
Below are the three logical layers with explanation what they do:-
- View: - This layer handles responsibility of taking inputs from end user, positioning of controls, look and feel, design, visuals, colors etc.
- Model: - This layer represents your middle layer objects like customer, supplier etc. It handles business logic and interaction with data access layer.
- View Model: - This layer is the bridge between model and view. It handles connection logic , data transformation logic and action mapping between model and view. For example it will have following types of logics as shown below :-
o Replicating and propagating data between views and models. When someone enters data in to UI or the
model gets updated this layer will ensure that the propagation of data happens between these entities.
o Handling data transformation from view to model and vice versa. For example you have a model which
has gender property with data as “M” for male and “F” for female. But on the View or UI you would like
to display as a check box with true and false. This transformation logic is written in the view model
View model also map UI actions to methods. For example you have “btn_Add” click event and when any one clicks on this button you would like to invoke “Customer.Add()” method from the customer class. This connection code is again a part if view model.
Recently one of our friends was asked to explain WPF dependency property , below is link which explains the same in great details http://www.dotnetinterviewquestions.in/a