Static Vs Instance Data Access Methods

  • Thread starter Thread starter michaeltours
  • Start date Start date
M

michaeltours

I've just finished writing a Data Access Layer for an n-tiered web application. However, a lot of the online literature I read whilst reading up on ADO.Net, espeially Microsoft Literature, had many code examples where the Execute methods were Static. Whilst I understand the basic principles and differences between Static and instance, I'm not sure what benefit one gets from using static methods for Data access

Can anyone explain

Thank

Mike
 
You don't need to instantiate a class to access a static. <-- that is what
the DAAB is using it for (I think that's what ur referring to).
If you create a static class with a non-default public constructor, the
compiler throws in optimizations that make the code run upto 8 times faster
(read Scott Allen's article regarding statics in MSDN Mag).

And on another note, it lets you share instance data between multiple
invocations of various classes.

Maybe there are a few more :), but those are what I could think off the top
of my head.

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik


michaeltours said:
I've just finished writing a Data Access Layer for an n-tiered web
application. However, a lot of the online literature I read whilst reading
up on ADO.Net, espeially Microsoft Literature, had many code examples where
the Execute methods were Static. Whilst I understand the basic principles
and differences between Static and instance, I'm not sure what benefit one
gets from using static methods for Data access ?
 
Sahil,

Do you have a link where I can read about the "compiler throws in
optimizations" bit of your reply.

By Non-default constructor do you jsut mean specifiying a constructor of
your own.

TIA

MattC
 
Back
Top