Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The role of the model in MVVM

Tags:

c#

.net

mvvm

wpf

I've read a few articles regarding the role of the (Data)Model in the MVVM pattern. However, i still could not figure what goes into the model.

Should the model implement INotifyPropertyChanged? If so, what is difference between the VM and the model?

If not, a change in the Model will not notify the VM and the View that it occured. So - considering the logic goes into the Model, it seems obvious that it should notify the ViewModel about some of it's changes. However, isn't it weird to implement INotifyPropertyChanged in both classes?

Thank you very much!

like image 557
Horse Pen Avatar asked Feb 17 '11 10:02

Horse Pen


People also ask

What are the responsibilities of ViewModel?

ViewModel's only responsibility is to manage the data for the UI. It should never access your view hierarchy or hold a reference back to the Activity or the Fragment.

What is the role of the ViewModel in the data binding?

The ViewModel is the centerpiece of MVVM. It has all the business logic and some of the display logic in it. The ViewModel needs to adapt the information in the Model for the Views to display. The ViewModel also transforms input events into data for the Model to store.

Why do we need model view ViewModel pattern MVVM pattern?

Model and ViewModel work together to get and save the data. View: The purpose of this layer is to inform the ViewModel about the user's action. This layer observes the ViewModel and does not contain any kind of application logic. ViewModel: It exposes those data streams which are relevant to the View.

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.


1 Answers

The model implements your business logic. The view model decorates your business logic for the purpose of displaying it and interacting with it, in a view (UI of some form, eg. web, winform, CLI). So, no, I would not say that your model should implement INotifyPropertyChanged unless it would do so as part of your core business logic.

like image 190
Klaus Byskov Pedersen Avatar answered Oct 01 '22 01:10

Klaus Byskov Pedersen