views:

179

answers:

1
+2  Q: 

From MVC to MVVC

I don't want to store my domain model classes in the same assembly as my web platform. The Models folder in the project structure is therefore useless to me. I've however just finished the Music Store Tutorial and noticed how they create a "ViewModels" folder which makes lots of sense to me.

Does it make sense to just treat the Models folder as a ViewModels folder? Do many people do this? Is there such a pattern as MVVC?

+2  A: 

A view model is something to add another level of abstraction in case you don't completely trust your presentation code (or simply find this kind of encapsulation more elegant).

That is, if your Person class has a Delete method or a SSNumber property, you might want to not pass this object to a view, as this, conceptually, enables it to call Delete or display the SSN, which it must not be able to.
To avoid this situation, you create another class, PersonViewModel, that only contains information/methods that are safe to be called from a view.

This has little to do with taking the model logic out of an MVC application. You can create a separate project for your model and reference it from your web application regardless of whether you use ViewModel encapsulation. Doing so is encouraged by books I've read so far.

GSerg