static method against class method

  • Thread starter Thread starter DBC User
  • Start date Start date
D

DBC User

I have a static class with bunch of static methods. That is my common
routines used spratically across the programs. I am wondering which is
the best coding and performance wise good standard. Try to put the
required methods in a class and use the class or keep the static on
most commonly used methods?

Thanks.
 
As always it depends ...

Do they share any kind of state? Then a class would be good.
Are the method non-reentrant? Then a class would be good (links to item #1)
Do you want to ever use polymorphism? Then a class would be good

If you answerred no to these cases .. Then a static class works well
conceptually and you are left with a design preference :)

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung
 
As you said, they are static. Keep things static if they don't need any
state. Things become simplier as you don't need to worry about state
leaking in, and you can just call them anywhere in your app without init().

--
William Stacey [MVP]

|I have a static class with bunch of static methods. That is my common
| routines used spratically across the programs. I am wondering which is
| the best coding and performance wise good standard. Try to put the
| required methods in a class and use the class or keep the static on
| most commonly used methods?
|
| Thanks.
|
 
Back
Top