Should all methods be static if their class has no member variables

前端 未结 20 2288
悲哀的现实
悲哀的现实 2020-12-02 14:18

I\'ve just had an argument with someone I work with and it\'s really bugging me. If you have a class which just has methods like calculateRisk or/and calc

20条回答
  •  不思量自难忘°
    2020-12-02 15:12

    It depends what your goal is:

    If your goal is to write as few lines of code as possible, the static approach would be the best.

    If your goal is testability, we've discovered that static methods are a bugger to mock out. We, sadly, end up writing an interface, and a class for some of these just to be able to mock them out easily.

提交回复
热议问题