开发者

What goes in Model in MVVM?

开发者 https://www.devze.com 2023-01-31 06:43 出处:网络
The things which are supposed to go into the Model are also allowed to go into the Vie开发者_开发技巧w-Model i.e. Public Properties, IDataErroInfo and INotifyPropertyChanged, then what should actually

The things which are supposed to go into the Model are also allowed to go into the Vie开发者_开发技巧w-Model i.e. Public Properties, IDataErroInfo and INotifyPropertyChanged, then what should actually go into the model?


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.


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消