Tuesday 15 January 2013

ASP.NET MVC with ViewModel

Many a times I have seen a team member get obsessed with a particular design pattern and implement it in its purest form. And then that slowly, in a few months, leads to problems because requirements keep getting added to the pile and the team tries to implement new requirements without violating the pattern and conformity. Those are the times when you need to think of mixing patterns and assess if that helps in keeping the implementation flexible and understandable.

One such case if MVC. As the UI screens keep getting complex, strongly typed views require changes in the underlying model. I think in such cases, MVC with ViewModel is a very good solution. It allows us to keep UI complexity in ViewModel without affecting the Model which is a good thing because the core business entities and domain model change at a much slower rate than the rate at which UI and services changes. It is pretty effective when we use strongly typed views in ASP.NET MVC applications.

Below are couple of nice articles that explain the advantage of using ViewModel in ASP.NET MVC applications.

http://nerddinnerbook.s3.amazonaws.com/Part6.htm

http://www.highoncoding.com/Articles/659_Implementing_ViewModel_in_ASP_NET_MVC_Application.aspx

This gives a fresh perspective into how we should look to mix and match different design patterns and find a hybrid pattern that best solves the given problem. Once you do that you ought to document it in detail too so that it does not create any confusion in the head of a new team member.

No comments:

Post a Comment