Maybe I'm crazy, but I g开发者_C百科et MVC. It makes sense. MVVM seems like a way to make MVC harder, am I wrong (if so, why?)?
I think that if you get MVC, then MVVM is really the same - with 1 additional part (the ViewModel). The reason that MVVM is more useful in my opinion has to do with the new DataBinding processes. The ViewModel provides useful abstraction and clarity about what is being databound, and how that binding is presented or converted. That's all it does in my mind.
The missing part from MVC is actually in the MVVM pattern, it's just the hidden part of MVVM in my opinion. If you look at most MVVM frameworks, most provide some sort of messaging or notification system, which really provides the missing Controller aspect of MVC.
Think of the ViewModel as the code-behind for your View, the View as the Designer of your View, the Model as the Model, and the Notification / Messaging system as the Controller, and we have a truely equivalent pattern.
This was a struggle for me to understand as well (I came from the MVC pattern as well, but now love the MVVM pattern).
Maybe this is helpful.
You don't need MVVM - it just works well.
MVVM is just an alternative. You are free to use MVC. MVVM just takes advantage of some specific features in WPF and Silverlight (mainly the amazing DataBinding support, but also templating and commanding) in order to make your life, as a developer, simpler. MVVM is particularly good as decoupling the View from the code - even more so than MVC, as using the DataBinding allows a designer to change the View much more effectively without worrying about code changes than MVC.
MVVM also has the benefit of being very closely related to the fundamental design principles behind WPF and Silverlight. The basic idea of MVVM is very similar to the design of WPF and Silverlight at a fairly low level - For example, look at how templating works with custom controls, and compare it to the View/ViewModel separation, and there are a lot of correlations that can be drawn.
精彩评论