MVVM Responsibilities - MVVM

What is MVVM Responsibilities?

MVVM sample includes three parts − model, View, and ViewModel. most of the developers on the start are little confused as to what a version, View and ViewModel must or shouldn't include and what are the responsibilities of each part.

in this chapter we are able to learn the responsibilities of every part of the MVVM pattern so you can truely recognize what type of code goes where. MVVM is really a layered architecture for the consumer aspect as proven within the following figure.

MVVM – Responsibilities

  • The presentation layer consists of the views.
  • The logical layer are the view models.
  • The presentation layer is the combination of the model objects.
  • The client services that produce and persist them both directed access in a -tier application or through provider calls in and then to your application.
  • The client services are not officially a part of the MVVM pattern however it is often used with MVVM to obtain in addition separations and avoid replica code.

Model Responsibilities

In preferred, model is the best one to recognize. it is the client side information model that helps the views in the application.

  • it is composed of items with properties and a few variables to include records in memory.
  • Some of the ones properties can also reference other model items and create the item graph which as a whole is the model objects.
  • Model items need to increase property change notifications which in WPF means records binding.
  • The last responsibility is validation that is optional, however you may embed the validation data on the version objects by the usage of the WPF information binding validation capabilities through interfaces like INotifyDataErrorInfo/IDataErrorInfo

View Responsibilities

The main reason and responsibilities of views is to outline the shape of what the user sees on the screen. The shape can include static and dynamic parts.

  • Static parts are the XAML hierarchy that defines the controls and layout of controls that a view is composed of.
  • Dynamic part is like animations or state changes which can be described as a part of the View.
  • The primary goal of MVVM is that there need to be no code behind within the view.
  • It’s impossible that there is no code behind in view. In view you at least want the constructor and a name to initialize aspect.
  • The concept is that the event dealing with, movement and information manipulation logic code shouldn’t be in the code in the back of in View.
  • There are also different varieties of code that need to cross in the code behind any code that is required to have a reference to UI detail is inherently view code.

ViewModel Responsibilities

  • ViewModel is the main point of MVVM application. The primary responsibility of the ViewModel is to offer information to the view, so that view can placed that information on the screen.
  • It also allows the consumer to interact with information and change the information.
  • The other key responsibility of a ViewModel is to encapsulate the interaction logic for a view, however it does not mean that all of the logic of the application need to go into ViewModel.
  • It need to be able to manage the precise sequencing of calls to make the right aspect show up based on user or any changes at the view.
  • ViewModel need to also control any navigation logic like deciding when it is time to navigate to a unique view.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

MVVM Topics