Utility class in Spring application - should I use static methods or not?

前端 未结 3 1409
北海茫月
北海茫月 2021-01-30 12:23

Let\'s say I have a utility class DateUtil (see below). To use this method a caller method uses DateUtils.getDateAsString(aDate). Would it be better to remove the static modifie

3条回答
  •  太阳男子
    2021-01-30 13:01

    I don't think so. A DateUtils class sounds like a pure utility class that doesn't have any side effects but just processes input parameters. That kind of functionality may as well remain in a static method. I don't think it's very likely that you'll want to mock date helper methods.

提交回复
热议问题