In what situations is static method a good practice?

后端 未结 11 1040
走了就别回头了
走了就别回头了 2020-12-04 10:04

I have read the following discussions:

Should private helper methods be static if they can be static , and
Should all methods be static if their class has no mem

11条回答
  •  萌比男神i
    2020-12-04 10:54

    Generally I avoid static methods when a single instance will work fine. That single instance can implement an interface and can be mocked easily. I'm not saying never but I rarely use statics. I tell my team if they want to use a static it should be cleared by the team. Almost never is my answer.

提交回复
热议问题