Is there anything wrong with a class with all static methods?

后端 未结 16 1100
余生分开走
余生分开走 2021-01-30 16:43

I\'m doing code review and came across a class that uses all static methods. The entrance method takes several arguments and then starts calling the other static methods passin

16条回答
  •  臣服心动
    2021-01-30 17:09

    Nothing is wrong with it. It is a more "functional" way to code. It can be easier to test (because no internal state) and better performance at runtime (because no overhead to instance an otherwise useless object).

    But you immediately lose some OO capabilities Static methods don't respond well (at all) to inheritance. A static class cannot participate in many design patterns such as factory/ service locator.

提交回复
热议问题