BACK
TOP
DotNet - Best Practices – Static Class
Matías Creimerman - Buenos Aires, Argentina - 2020-02-17

A static class is one that is defined only with static members (because they do not represent objects but functionality). Its usefulness is to extend functionality or to define operations that do not require an object in itself, for example, you could create a static class that has methods to check file states without the need to instantiate an object that represents the file, such as "if it exists" functions, deletion, creation, etc. Or an extension of a certain type, for example of the strings, and add functionality inherent in any string. When defined, it is sealed, abstract and its members cannot be redefined or redeclared.

As a good practice, it is to consider static classes in appropriate cases, not to use them for everything. It should be support functionality and not the functionality itself of the objects or types of objects involved. Nor should you override their methods or redefine or add to them. Always mark them as sealed and abstract.

This content is property of Matias Creimerman
Any misuse of this material will be punishable
This work is licensed under a
Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License
Creative Commons License