View Single Post
Old April 17th, 2007, 12:53 AM
englere englere is offline
Friend of Wrox
Join Date: Jun 2003
Location: Atlanta, Georgia, USA.
Posts: 917
Thanks: 0
Thanked 0 Times in 0 Posts

>the Directory class exposes static methods and the DirectoyInfo class contains instance methods. The former is good for one time use while the latter is good for repeated called of its methods.

Static methods are always more efficient if you don't have to maintain state. It's critical that you get this, or you'll miss the boat. Consider why it's better to have an object instance: specifically so it can remember some of your data between method calls. That's what "state" means. Static calls are fast to dispatch, but they can not maintain any state for you (apart from the possibly of static fields).

Please re-read my message. The code is NEVER copied, regardless of how object instances you have, and how many people hit your site. But it makes sense for you to use a web garden or web farm to help in that regard.

From a design perspective, any extra class instances that aren't needed, and especially those that are unique for each user, will slow down the site and be a drain on server resources. Static objects always make more sense unless you need to retain information.

In ASP.NET you can only maintain information for the time it takes to process one postback unless you utilize the cache, session state, application state, etc. A normal object instance can not survive a page cycle unless it's persisted in some way. So you don't want to be creating a bunch of extra short-lived objects that you don't need because they'll pressure the server; especially in a garbage collection sense. Only create object instances that you need: that will benefit you in some way. Otherwise, use statics.