I’m just learning the ropes of the MVVM pattern in WPF applications, and I can imagine that this sounds like an incredibly stupid question, but here goes anyway:
I already have a model in one assembly, which is a simple class library. In a different assembly, I’ve created a simple view in xaml. Now the books all tell the same: link them together with a viewmodel. My question is though, where does this viewmodel belong:
- Is it more or less part of the view, and should it be in that assembly?
- Is the viewmodel meant to be universal, so it belongs together with the model assembly?
- Does the viewmodel get its own assembly?
I know the MVVM pattern is merely a design guideline and not a strict set of rules, but I feel it’s better to learn things the right way.
EDIT
Follow-up question: is a viewmodel meant to be re-usable? I can imagine a scenario where it would be usefull if you could use the same viewmodel for a WPF desktop application and a silverlight web application.
It facilitates building the view, so it belongs in the view assembly.
Think of it like this: could you take your model assembly and use it in a different style of application, e.g. a Windows service or a web application? Is there anything that is irrelevant to that style of application in that assembly? If the answers are yes and no, you’ve built yourself a useful re-usable component that is independent of the type of user interface.