Normally in application development projects of any type we come across some sort of Utility classes, which has a bunch static methods for Date ,String .. etc manipulations.While reviewing code for the past few years I have seen two problems
- Some developers using object instances to access this methods without looking into the fact that they are static methods.
- During initial design & coding there are only static methods but down the line during support instance methods are getting added.
So we need to have a way where we can stop the instantiation of the class and addition of instance methods to it.
One option to do it in .NET 1.1 was making the class sealed with a private constructor.But that does not stop anyone from adding instance methods(of no use though) and private constructor takes up unnecessary metadata space.
In .NET 2.0 we have static classes for this purpose which can have only static members and can never be instantiated.