Functions vs. Static Methods

前端 未结 4 1866
心在旅途
心在旅途 2020-12-16 15:01

I\'ve got a few functions that deal with cookies. Would it be a horrible idea to group them by moving them to a class of their own and use them as static methods?

F

4条回答
  •  不知归路
    2020-12-16 15:35

    It would be a great idea, provided you are fully aware of the caveats involved. This is known as the Utility Pattern:

    Good candidates for utility classes are convenience methods that can be grouped together functionally.

提交回复
热议问题