Is it bad practice for a class to have only static fields and methods?

后端 未结 14 711
予麋鹿
予麋鹿 2020-11-30 03:05

I have a class that consists only of static member variables and static methods. Essentially, it is serving as a general-purpose utility class.

Is i

14条回答
  •  一生所求
    2020-11-30 03:29

    I wouldn't be concerned over a utility class containing static methods.

    However, static members are essentially global data and should be avoided. They may be acceptable if they are used for caching results of the static methods and such, but if they are used as "real" data that may lead to all kinds of problems, such as hidden dependencies and difficulties to set up tests.

提交回复
热议问题