Understanding View Models
A view model represents the state and behavior of a particular piece of UI—it is the non-framework-specific analogue of a control. Just as you can’t generally place the same control instance in two locations in a UI tree, you can’t also reuse the same view model instance.
If you could, we’d call it a
ViewsModel
🙂
–Bryan Watts
I remember spending time when learning MVVMlight debugging issues around the reuse of view models, and I thought such reuse was integral to MVVM. In then end, and with much regret, I tore out all this reuse, replacing it with very simple code that created a new view model when views were instantiated. I felt awful, scrapping the work that went into MVVMlight to do this. And yet, after reading the above quote, I feel a little vindicated. I’m sure there’s cases where you might want to keep a viewmodel instance around, but I’m still suspicious if this should be the default behavior.
Leave a Reply
No trackbacks yet.
No post with similar tags yet.
Posts in similar categories
Capricious Whim
“Einstein argued that there must be simplified explanations of nature, because God is not capricious or arbitrary. No such faith comforts the software engineer.” —Fred Brooks