Library tutorials & articles

Boosting Your .NET Application Performance

Class Design

Let's talk about class design. It's very interesting to see what Microsoft recommends to us, the developers. If you've worked with the IBuySpy portal or store, then you will know what I mean.

C# and VB.NET are both .NET languages that emphasize good object design using consistent design patterns whenever possible. Microsoft worked hard to get VB.NET to become an OO language too, but what Microsoft recommends for a web application is a little different.

IbuySpy, which Microsoft calls "a collection of best practices" for a .NET web application has a class design that doesn't really follow the Object Oriented approach. IBuySpy has only one Middle Tier, which combines BLL and DAL. That middle tier consists of relatively thin engine classes that only wrap SQL Server stored procedures.

Although some people say IBuySpy has a very bad design, in my opinion it’s a great design. It's very fast (due to a minimal number of roundtrips to the database) and its complexity is reduced considerably by combining the BLL with the DAL. If you are designing a Content Management System or something of the like, then this is the best way to do it.

You can develop these applications quickly too. Though, one place where this falls down on is in its code elegance, hence it's harder to extend or modify the application in the future. It is designed like a procedural program; with functions not object oriented programming with objects and methods. When you try to upgrade or add functionality to these applications you will have a hard time understanding the application.

So, if you are designing a huge enterprise solution, this definitely isn't the way to go. Also, if you have more than one type of client, for example, if your business tier feeds data to both WinForms and WebForms, then you might want to consider a different design. This is especially the case for WinForms, as passing a DataReader through the network isn't such a good idea as a connection is opened during that transfer. Use a dataset or custom collection for this instead!

So what are the alternatives? I think there are many good alternatives, but a collection / class design is the best one in my opinion.

Basically, each entity consists of two classes. One is the entity (e.g. User), and one is the entity collection (e.g. UserCollection or Users). An entity class contains properties that describe the entity (e.g. Name, Email), as well as methods to update the data. A collection class is ultimately a child of an ArrayList class. It will have methods to fill up the collection (e.g. GetAllUsers, GetAdministrators, GetRandomUsers), enumerate through the collection (eg MoveNext, Current, Reset), delete an entity, and finally add an entity.

By using this design, your source code will be much easier to understand and modify in the future. One disadvantage of this is that the performance is compromised due to having more objects and round trips to the database.

This design is good for business tiers feeding data to multiple types of clients -- e.g. WinForms and WebForms -- because it uses a disconnected data model, much like typed datasets but a little lighter in features and far superior in performance. You can even pass it through the network without holding the connection to the database.

I use this design for relatively large web sites or solutions that need support for multiple client types.

Comments

  1. 06 Mar 2009 at 08:19
    hi , Really an excellent topic which clears the n-tier Archetecture specially for begineers. Thanks Dileep Rawat
  2. 30 Dec 2008 at 11:34
    Hi, Very nice article for .Net begineers. Good effort... Thanks, Vijay G
  3. 15 Jun 2008 at 17:30

    This is one of the BEST article on 3-Tier design.....

    Excellent Efforts....

    Thanks a lot,

    Dattaprasad

  4. 08 Jun 2007 at 07:30
    Hi, Its really make sense.

    Thanks,
    Anmol Gupta




  5. 01 Mar 2007 at 03:50

    Tier and layer do NOT mean the same thing . According to http://codebetter.com/blogs/david.hayden/archive/2005/07/23/129745.aspx

    Tier is more about where the code / processes run (physical location), and Layer is more about how the code is logically grouped. 

  6. 03 Jul 2006 at 07:31

    Hi

        Of Course it is a very useful topic from the point of view of an interview also. It provides a great help.

    Thanks

  7. 07 Feb 2006 at 08:53

    The topic explained is very useful especially for a .Net beginner. Practically these things counts a lot when working on big application\projects.

  8. 20 Jan 2003 at 14:50

    A helpful practice I first read about in Advanced Visual Basic 6.0 by the Mandlebrot Set Intl. Ltd. was to store the recordset/dataset/custom collection data in the collection class and make the properties of the contained object point back to a row or item in that set. Saves many, many data operations over time, and thus boosts performance.


    -rory 8)

  9. 01 Jan 1999 at 00:00

    This thread is for discussions of Boosting Your .NET Application Performance.

Leave a comment

Sign in or Join us (it's free).

James Yang James is a student at Georgia Institute of Technology, majoring in Computer Science. He is an MCSE, MCDBA, MCSA and CCNA.
AddThis

Related discussion

Related podcasts

  • More jQuery in ASP.NET

    In this episode Chris Brandsma, Rick Strahl, Dave Ward, Bertrand Le Roy, and Scott Koon conclude their discussion of Microsoft's jQuery in ASP.NET announcement1.This episode of the Alt.NET Podcast is brought to you by LLBLGen Pro, the most mature O/R mapper and code generator out there.Are ...

Events coming up

  • Nov 18

    15 Minutes of Fame

    Dresher, United States

    This is a yearly tradition. We select 10 of the favorite speakers from monthly meetings, code camps, and hands on labs. Each one does a 15 minute talk on their favorite .NET technology. This is our 10th anniversary so we plan a gala event with special prizes and refreshments.

Want to stay in touch with what's going on? Follow us on twitter!