Should I prefer static methods in C#

前端 未结 6 1345
一整个雨季
一整个雨季 2021-02-05 08:47

Having spent a bit of time learning about functional programming, it\'s becoming more and more natural for me to want to work with static methods that don\'t perform any mutatio

6条回答
  •  旧巷少年郎
    2021-02-05 09:12

    There is many reasons should curb this instinct when you write OOP.

    Object states and behaviours;

    Static class and method need parameters, and you should be sure which paramters will pass to static methods. But class manages itself if method related with is state.

    I think that only this reason enough to curb static modifiers.

    And for clear reason, we should listen Mrs. Liskov. here

提交回复
热议问题