Web forms vs. MVC
I just finished my very first web forms project. Yes it's really true. I have never had any real hands on web forms before. When I started programming web stuff in ASP.NET I went directly from PHP5 to ASP.NET MVC Preview 2.
When I was working with PHP, I used the joomla open source CMS, which implements the MVC design pattern. Yes, MVC is actually a design pattern rather than something new fancy stuff that Microsoft invented. Microsoft, however, did what they do best; Go all the way with their ideas which resulted in the fabulous ASP.NET MVC framework.
Anyway, what I realized, while working with the classic web forms project, was that it's quite possible to implement the MVC design pattern even though there's nothing "MVC" visible anywhere.
Consider the following as your controller:
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
PersonRepository pR = new PersonRepository();
pR.addPerson(textfield.Value);
Response.Redirect("~/Default.aspx", true);
}
}
The controller's job is to take values from the view, and hand them on to the Model which does the actual business logic. The snippet above, takes a string from a text input field, and parses it in a repository. Then redirects the user to Default.aspx.
In the snippet above, the PersonRepository represents the Model because it is domain specific. The Model does not know anything about the view.
Using a domain driven design, is essential for us to gain the MVC pattern. But if we do so, we are rewarded instantly when we want to create unit tests for all of this. The ASP.NET MVC framework however, is a lot easier to unit test than web forms.
For me, the major difference between web forms and ASP.NET MVC, is that the horrible runat="server" tags are gone!
Praise the lord!