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 MVVM?
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.
I think you refer to the MVVM pattern (Model-View-ViewModel)
There is not such a thing like MVVC.
The Domain Model is designed in terms of business logic and business abstraction, it is targeted to solve business problem maybe utilizing object oriented techniques, the result is a domain model with entities and value objects references each others and interact with others to achieve the business logic goals.
Presentation on the other hand is a different perspective, you mostly needs to flatten the domain objects to make it easier to bind, you also may not be interested of some attributes and properties of the domain model entities in the presentation layer, thus the presentation model (View Model) is a more customization of the model for view purposes, the structure could be different, you may remove some fields that are unneeded for presenataion and also add some fields just for presentation purposes (like "IsIdEnabled" or SliderWidth, ...)
As Dx_ stated above, there is not such a thing like MVVC.
But, this fine talk describes MVVM very well: Deep Dive MVVM
精彩评论