Patterns in .NET

Andrew makes some obversations about MVC in the .NET world.

I too have been delving into OO principles and patterns over the last couple of years. I'm still getting my head around the ups and downs of page vs front controller. ASP.NET uses a page controller pattern and frameworks such as Struts, Rails, and several PHP frameworks use the front controller pattern.

There's some really good reading on these patterns in Fowler's Pattern of Enterprise Application Architecture. Also read everything you can on www.martinfowler.com.

You can still implement front controllers in ASP.NET using an HttpModule or .ashx. The thing that turns people off to this is you ditch most of the IDE support for designers and most of the features that webforms give you (viewstate, postback etc). This is where you have to look around at some other frameworks that implement a front controller. Castle MonoRail and Spring.NET are two major ones that I have found.

MS also seems to be getting more an more on the OO/Patterns bandwagon ever since .NET was introduced (Or maybe this is just when I started the transition). For example, the provider model in ASP.NET 2.0 is really awesome. You should def be using it to decouple your web tier from your biz/data tier. Check out this MSDN article on the provider pattern.

If you want to go swimming in an ocean of patterns take a look at Enterprise Library 2.0. Lots and lots of good stuff in there.

Another great book on practical application of patterns and refactoring to existing code is Feather's Working Effectively with Legacy Code.

3 Comments

  • You should also take a look at http://weblogs.asp.net/pschneider/archive/2006/06/09/Head-First-Design-Patterns-Samples-in-C_2300_.aspx

  • Most people don't need to implement HTTP modules or handlers, so the point is almost moot. I wouldn't stress too much between trying to implement page vs front controller. Try to focus more on the technical need of a module/handler and go from there. Recognizing the patterns is great, but I think the examples on MSDN for both of these might be bad. They're correct, but I think they probably could've chosen something to better exemplify their purpose and why you'd choose one over the other -- something that was a bit more contextual, maybe. Just my opinion.

  • Patterns in NET.. I like it :)

Comments have been disabled for this content.