Why Two Classes, View Model and Domain Model?

I have found that while my domain model gets me 85% of the way to having the fields I want, it has never covered 100% of the values I want on my view. Especially when it comes to permissions and whether or not a user should have access to certain portions of the view.

The design concept I attempt to follow is to have as little logic in my views as possible. This means I have fields in my view model like “CanViewThisField” or “CanEditThisField.” When I first started with MVC I would have my domain model be my view model and I was always running into the scenario where I needed just one or two more fields to make my view less cluttered. I’ve since gone the View Model/Model Builder route and it has worked wonderfully for me. I don’t battle my code any longer but am able to enhance my view model as I need to without affecting the domain model.

Leave a Comment