Should you use all static classes for middle and data tiers?

Discussion in 'ASP.NET 2.0' started by Joseph Jun, Jul 20, 2007.

  1. Joseph Jun

    Joseph Jun DiscountASP.NET Staff

    It's not a question that you'll ever get a straight answer to as there are two schools of thought that will always argue regarding this topic but I think what you should factor in is the environment variable.

    For instance, if your application is being hosted in a private environment where you have control over the system resources on the server then you'd be able to get away with high memory usage a bit but if your web application is in a shared hosting environment like DiscountASP.NET, you'd probably want to limit the memory usage of your application as the last thing you'd want is some undesirable effect like have your application pool recycling frequently.

    Like I said, I don't think you'll EVER get a straight answer but hopefully this provides a little food for thought.

    Winston

    DiscountASP.NET
    www.DiscountASP.NET
     
  2. For those of you using a three-tier layered architecture, do you think it's best to use static classes/methods or instantiate a new object for each call? I've noticed all the MSDN examples use non-static classes, but many other website examples use static classes in the Business logic and data access layers.

    It seems like static classes would be faster, since there's only one copy of each class and it doesn't have to be created/destroyed for each reqest. But I've read other sites that says this uses more memory, and you should create/destroy each class for each request.

    For example, say I'm posting user-submitted comments.I have abusinees-layer 'commentManager.cs' class that takes the request from the presentation layer, and a 'commentDataAccess.cs' class that calls the database.

    If they're not static, then the 'HomePage.cs' code-behind class has to instantiate a new commentManager() class, which creates a new commentDataAccess class, gets the data, and then both are destroyed at the end of the request. That seems much slower than having permanent static classes in memory.

    I'm a hobbyist, so any thoughts from the pros would be welcome. Thanks!
     
  3. You're right, my real question should be "which is best for apps hosted by discountASP.net"?

    And from what you say it would seem to be the one that uses less memory.

    But wouldn't static classes also use less memory? Again, I read that MS recommends instantiation over static classes, but it seems like static classes would use less memory since (I think) there's only one copy of the class for all users. Is that correct?

    Thanks again for the ideas,
    Jason
     

Share This Page