Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
As I understand it, MVVM works like this:

Imagine I have a view with a button to calculate tax.

This calls a method in the view-model that updates the tax in the model

the model then issues a INotify to the View saying 'Tax updated'

the View then goes to the model, grabs the updated value and places it in the view thus displaying it to the end user.

---

this last part seems to be an additional unnecessary something to do. Why doesn't the model simply INotify the view with the updated value?

Or, have I missed something?

What I have tried:

googled for an understanding and checked the explanations here on code project
Posted
Comments
[no name] 15-Dec-17 14:36pm    
"Why doesn't the model simply INotify the view with the updated value":
Because the Model has no knowledge of the View
Member 13578639 15-Dec-17 15:48pm    
but [as I understand it] the view has no knowledge of the model either.

The model knows enough that it needs to notify the view that a value has changed, why not pass it the value at the same time rather than waiting for the view to 'request' the value.
Dave Kreskowiak 15-Dec-17 16:05pm    
No, the model knows enough to raise an event that any subscribers will get notified of the changed value. It knows nothing of what subscribed to it. The subscriber, in your case the View, gets the event notification, then determines on its own whether to go get the new value or not. What if the value isn't being displayed in the current mode or is "off screen" and shouldn't be updated? That's up to the View to determine, not for the Model to force on the the View.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900