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

后端 未结 14 702
予麋鹿
予麋鹿 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:20

    As long as the class has no internal state and is essentially what is known as a leaf class (utility classes fall into this category), in other words it is independent of other classes. It is fine.

    The Math class being a prime example.

提交回复
热议问题