Utility classes.. Good or Bad?

前端 未结 8 708
暗喜
暗喜 2020-12-24 15:19

I have been reading that creating dependencies by using static classes/singletons in code, is bad form, and creates problems ie. tight coupling, and unit testing.

I

8条回答
  •  粉色の甜心
    2020-12-24 16:20

    I agree with some of the other responses here that it is the classic singleton which maintains a single instance of a stateful object which is to be avoided and not necessarily utility classes with no state that are evil. I also agree with Reed, that if at all possible, put these utility methods in a class where it makes sense to do so and where one would logically suspect such methods would reside. I would add, that often these static utility methods might be good candidates for extension methods.

提交回复
热议问题