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!
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.
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.
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.
Model is the layer that drives the business logic. It retrieves and stores information from any data source for consumption by the ViewModel.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With