Making Methods All Static in Class

前端 未结 10 1338
离开以前
离开以前 2021-01-04 12:10

I was told by my colleague based on one of my classes (it is an instance class) that if you have no fields in your class (backing fields), just make all methods static in th

10条回答
  •  甜味超标
    2021-01-04 12:17

    It sounds like you're talking about a strictly Utility class, in which case there's really no reason to have seperate instances.

    Make those utility methods static. You can keep the class as a regular object if you'd like (to allow for the future addition of instance methods/state information).

提交回复
热议问题