Why are static classes used?

后端 未结 6 1049
故里飘歌
故里飘歌 2021-01-17 23:23

I have doubts on static class and static methods. From MSDN I understood that \"Static classes and class members are used to create data and functions that can be accessed w

6条回答
  •  走了就别回头了
    2021-01-17 23:43

    For utility classes they are great. As you mentioned, they are similiar to global state. So for classes which have no state, for performance benefits the class should be static.

    On the other hand, static classes are hard to test (if they contain state). Polymorphism and other OO concepts are also lost.

    Use wisely.

提交回复
热议问题