开发者

One category per method vs. all methods in one category? (ObjC)

开发者 https://www.devze.com 2023-01-05 10:55 出处:网络
Should I put all my methods in one category (I mean for the same kind of object) or should I spli开发者_如何学Got them up in many files? (Something like NSStringAdditions vs. NSString+this and NSStrin

Should I put all my methods in one category (I mean for the same kind of object) or should I spli开发者_如何学Got them up in many files? (Something like NSStringAdditions vs. NSString+this and NSString+that)


That very much depends.

If they are closely related to each other, put them in the same category. If they solve quite different tasks, then splitting them is appropriate.

Also, reusing in different projects my be a point to consider.

Always treat categories with care, though. Although it is possible to extend existing classes, and in some cases it is justified use, don't abuse them. They come at a cost (performance, flexibility, maintenance). So if you have to decide to split your category, this is most of the time a sign for too much complexity here, and a subclass or other helper class is the better choice.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号