views:

63

answers:

3

I am trying to understand the ASP.NET WebForms and MVC from the point of view of understanding the design patterns used. While MVC clearly looks like an implementation of FrontController, I am not very sure about WebForms pages. So, I would appreciate if anyone can help with the following questions around this.

  1. Is WebForms based on a PageController pattern?

  2. Are Front Controller and Page Controller both modified versions of MVC?

  3. Can WebForms also be called a special case of MVC where distinction between controller and view is blurred?

Finally, are there any good resources on the web that can provide a detailed reference on this topic?

+3  A: 

ASP.NET MVC is based on the Front Controller design pattern. Classic ASP.NET WebForms are based on an effort from Microsoft to bring Windows Forms event model to the web by hiding and abstracting many parts and you could apply the page controller pattern but out-of-the box it is not.

Darin Dimitrov
A: 

Following the order of your questions:

1//No. Webforms are based on the the "Smart UI" pattern, ie, you control the app by writing event handlers. Smart UI has its issues, but when entirely based on the desktop it works OK, in the sense that no major "fiction" is introduced into the framework for it to work. With the web, however, that works over stateless HTTP, a major fiction is introduced, essentially in the form of the ViewState that holds the state of all the controls when the page was sent to the client browser. As a result, web forms introduce a layer of complexity into your applications that is only there to sustain this ficiton. MVC eliminates this fiction.

The fiction essentially says: We will pretend that HTTP is not there between us and the client.

2//MVC removes the fiction and gives you naked HTTP. However it is more based on the Front Controller than the Page Controller pattern in that the Page Controller pattern makes testing the controller independently of Http requests is difficult, whereas MVC is specifically designed to make the controller testable independently of HTTP requests. In other words, MVC is designed to enable unit testing on the controllers as opposed to integration testing.

MVC focuses on the separation of the Model from the View, whereas Webforms/Smart UI does not make this distinction.

I suppose you could say, to eliminate the Page Controller from ASP.NET MVC, that ASP.NET refactors the impact of HTTP on the controllers to "orthogonal attributes", which is not the way I am led to believe that the Page Controller pattern works. However, don't quote me on this, I am a student of these things, not an expert.

3//No definitely NOT! As discussed above, webforms are fictional smart ui, NOT MVC in any shape or form. You can go through a few hoops to make them sort of MVC ish (a la Dino Esposito), but this is again a ficiton. Why indulge in the fiction if you have ASP.NET MVC?

A final broadside. The reason I switched from webforms to mvc was the Wizard Server Control. Its "Event Model" is a thing of cruelty that flies in the face of everything I needed to achieve (not to mention the choking proliferation of other properties, methods... Yuck!).

In 10 days I wrote a base WizardController and now my wizards are things of beauty, elegance and simplicity. I have joyfully thrown away 3 months of work on wizards in webforms to convert them to my new mini wizard framework. It is THAT bad.

awrigley
A: 

As far as references on this topic I would recommend both the book "Microsoft .NET: Architecting Applications for the Enterprise" by Dino Esposito and Andrea Saltarello as well as Dino's ASP.NET Presentation Patterns article.

Hector