Friday, April 22, 2011

My Cookbook on DTO and ViewModel

Load DTO, pass it to ViewModel(either by composition or inheritance), pass the ViewModel to View.



DTO has no behavior, it's just data; ViewModel not only has data, it also has behavior, i.e. anything seen or interacted by the user, e.g. paging, dropdown's data , and other miscellaneous information(e.g. user can see the most selling product while he/she is in data entry page, that information are passed to ViewModel) seen by users are orchestrated in ViewModel



I'm starting to believe that ASP.NET MVC should be called ViewModel-View-Controller. VMVC, any takers? View doesn't interact with pure Model anymore, View has many concerns too(e.g. paging, alert message) that if it pull all this informations by itself, the program won't look cohesive anymore.


The Controller manages this complexity by assembling all the information needed by View in one cohesive model, which is differently termed(ViewModel), so developers won't have a misconception that a View is ought to deal with several raw Model by itself.



If the ViewModel pattern is not adhered to, an unwitting developer could badly stash all Models and miscellaneous information to ViewData dictionary or ViewBag

No comments:

Post a Comment