Question about your design choice

May 2, 2010 at 9:24 PM


I have to say that this code example is the best example I've seen when it comes to explaining how experienced developers design a web application. Not too complicated, only enough code to show how to set up the architecture.

I have question to either Jon, James or Howard. I'm wondering why you chose to use ViewModels and FormModels for all views and controllers. Why didn't you use the SharpModelBinder to bind directly to an entity when posting a form and only use view models when necessary? It seems to be a lot of extra work, both computer power and mapping handling in code. I know you have a good reason to do so but I can't see it.

Thanks for your contribution!


May 3, 2010 at 6:52 PM

Thanks for the compliment!

I might have to answer this question in reverse - the reason SharpModelBinder exists - is because if you follow Sharp Architecture out of the Box - it's all about making CRUD operations simple - what we're trying to demonstrate with WCHM is what an enterprise web app looks like - what things you need to think about when building a large, scalable application that needs to be testable and maintainable. This is a slightly different requirement and thus leads to some other design decisions. ViewModels / FormModels are there to allow you to create a thin layer that supplies your view with all the data it needs - this can be totally different model from your domain - the only real problem with WCHM is that it may be too simple an example to get across this intention.

James also posted an item in his Q&A - which talks a little about the choice:

What is the difference between a ViewModel and a FormModel? Is this really necessary? Why are they not all named ViewModel?

A viewmodel is an object used to bind to a view (i.e. for display purposes) and a formmodel is an object used to bind to a set of form parameters (i.e. when an HTML form is submitted). We’ve found that keeping display and update models separate is definitely preferred as they’re rarely the same and serve different purposes. For example, a formmodel is likely to have validation requirements that a viewmodel wont. We’ve found that this naming convention works – the use of view or form is explicit enough to describe what the purpose of the class is. Some people take this a step further and use ViewModel, EditModel, CreateModel, DeleteModel however we’ve found this to be overkill in the applications we have built. However, in a heavy CRUD style application, this may be preferred.

Hope this helps,


May 4, 2010 at 8:50 AM

Thanks, Howard,

It helped a lot!