In what situations is static method a good practice?

后端 未结 11 1054
走了就别回头了
走了就别回头了 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条回答
  •  时光说笑
    2020-12-04 10:59

    First of all, you can't dismiss static-methods there is a reason people still use it.

    1. some design patterns are based on static methods, singleton for example:

      Config.GetInstance();

    2. Helper functions, lets say you have a byte-stream and you want a function to convert it into a string of Hex numbers.

    there are many uses for static-methods, saying that does not mean that some people abuse it too much(Code Review is best option when people abuse code).

提交回复
热议问题