PDA

View Full Version : Where should I put this code?




merican
Feb 20, 2012, 08:42 PM
Say I want to add a method somewhere that allows the parsing of an NSString into NSColor, as well as a method for printing out a NSColor into a NSString; The NSStrings have the same syntax of an SVG's color attribute. Where should I be adding these two methods? Should I write a new class "NSColorParser" and "NSColorPrinter" and add the methods there or create a new category for NSColor, adding methods "colorFromSVGAttribute:" and "svgAttributeValue"?



lee1210
Feb 20, 2012, 09:14 PM
Wherever makes most sense to you. They should be class methods if they are on a utility class. It seems like a factory on NSColor is reasonable for getting an NSColor from the NSString. If you are adding these to NSColor, an instance method to get the NSString with your representation would work fine. Make sure to autorelease the objects you return if you use the names in your post.

-Lee

merican
Feb 21, 2012, 04:23 AM
I went with the factory. Thanks!