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

前端 未结 20 2336
悲哀的现实
悲哀的现实 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:08

    Imo, they should be static. I see no reason why they shouldn't be, since instance objects would have no state, and calling the methods without instantiating would require less code and thus improved readability.

    Actually, i would probably make sure the class won't be instantiated by making it abstract.

提交回复
热议问题