Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What goes in Model in MVVM?

Tags:

mvvm

wpf

The things which are supposed to go into the Model are also allowed to go into the View-Model i.e. Public Properties, IDataErroInfo and INotifyPropertyChanged, then what should actually go into the model?

like image 519
ns12345 Avatar asked Dec 15 '10 18:12

ns12345


People also ask

What is the model in MVVM C#?

Model is the layer that drives the business logic. It retrieves and stores information from any data source for consumption by the ViewModel.

How do I create a ViewModel in MVVM?

1 - Create all the properties in the customer again on the view model. Inject the customer instance into view model and each properties will retrun the value from this customer object. Advantage of this method is that I can create a common base class for all view models and have common functionality dumped there.

How can you explain the concepts of view and ViewModel in MVVM?

The viewmodel of MVVM is a value converter, meaning the viewmodel is responsible for exposing (converting) the data objects from the model in such a way that objects are easily managed and presented. In this respect, the viewmodel is more model than view, and handles most if not all of the view's display logic.

What is model in MVVM Android?

MVVM stands for Model, View, ViewModel. Model: This holds the data of the application. It cannot directly talk to the View. Generally, it's recommended to expose the data to the ViewModel through Observables. View: It represents the UI of the application devoid of any Application Logic.


2 Answers

Model

Business Data + Business Logic + Business Rules

View

Application UI

ViewModel

Wrapper Over Model which is easily readable/bindable by View using minimum Effort/Code.

  1. IDataErrorInfo - Should go into ViewModel
  2. INotifyPropertyChanged - Should go into ViewModel. Could also go in the Model if necessary (But not recommended)
  3. Public Properties - Yes of course a Model should have them.
like image 99
decyclone Avatar answered Oct 14 '22 04:10

decyclone


Assume you are going to write a batch process for a data load. The batch process will only access the model, thus everything you need to process the business rules divorced from the UI belongs in the model. The ViewModel may have some business rules but only as they pertain to the UI.

In the application I am building, the Views and ViewModels are in one assembly and the Model in another. The model has no references to the View's assembly and only the Model assembly has references to the underlying data store (a combination of Linq and web service calls).

like image 29
dave Avatar answered Oct 14 '22 04:10

dave