Building a Simple Blog Engine with ASP.NET MVC and LINQ - Part 4
page 4 of 8
by Keyvan Nayyeri
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 8137/ 457

Abstraction and Isolation in ASP.NET MVC

We need a good level of abstraction and isolation, but how we can achieve it in our design and code? This is possible via abstract base classes and interfaces because both these concepts provide some level of abstraction for us.

Unit testing is tight to abstract base classes and interfaces and there are lots of patterns and practices around these. I do not want to step into this topic here.

When you use abstract base classes and interfaces for abstraction then you are able to test instances of these classes easily because they all have some main methods that you need to call and use. This is very helpful when unit testing because it gives you much control on the classes that play a role in your testing units.

But how does one choose between abstract base classes and interfaces? Even though they both provide abstraction for us, each of them has some limitations for its own.

Phil Haack, my dear friend and a member of ASP.NET MVC team at Microsoft, has some blog posts that explain these limitations and what they faced with usage of interfaces in first CTP of ASP.NET MVC framework that forced them to switch to abstract base classes in the second CTP and most likely all the future versions.

·         Versioning Issues With Abstract Base Classes and Interfaces

·         Abstract Base Classes Have Versioning Problems Too

·         The Cost Of Breaking Changes

From an end user point of view, you may not care much about such stuff though!

But finally Microsoft applied abstract base classes for abstraction purposes in the second public release of ASP.NET MVC.

You see that these changes help you to unit test an ASP.NET MVC application in the next sections of this article.

Microsoft has moved all these abstractions and classes to a new assembly called System.Web.Abstractions so you can traverse through the classes in this assembly to see what is there.

Figure 1 shows all these classes with their hierarchy and structure which can give you some thoughts about this abstraction level.

Figure 1

As you see, here there are seven pairs of base classes and some classes that derive from them. All these abstract base classes are representing some traditional ASP.NET classes that had many dependencies. So this abstraction can help the unit testing process as you will notice this later in the next part.

But in a nutshell, we can group these classes into seven categories:

·         HttpSessionState

·         HttpServerUtility

·         HttpContext

·         HttpResponse

·         HttpRequest

·         HttpBrowserCapabilities

·         HttpCachePolicy

As you see, all these categories are strongly tight to server, client properties and characteristics, but this new abstraction helps to reduce these dependencies and improve the testability.


View Entire Article

Article Feedback

Title:  
Name:  
Url: ( Optional )
Comment:  
Please add 4 and 3 and type the answer here:

User Comments

Title: KBlog DEMO   
Name: Jame
Date: 6/19/2008 10:35:05 PM
Comment:
Can you provide the KBlog DEMO download address?
Title: MVC   
Name: Asmi
Date: 6/9/2008 5:24:51 AM
Comment:
Nice Article!! Waiting for the next to implement these practically.........
Title: MVC   
Name: Basheer Ahmed
Date: 5/17/2008 2:58:30 PM
Comment:
trp to put all series in one pdf file format
Title: sweet   
Name: Johan
Date: 5/13/2008 3:59:36 PM
Comment:
Nice article, looking forward for the next one.






Ads Powered by Lake Quincy Media
Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2008 ASPAlliance.com  |  Page Processed at 7/4/2008 11:05:00 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search