3. Interface and API Design
Item 15: Use Prefix Names to Avoid Namespace Clashes
- Choose a class prefix that befits your company, application, or both. Then stick with that prefix throughout.
- If you use a third-party library as a dependency of your own library, consider prefixing its names with your prefix.
Item 16: Have a Designated Initializer
- Throw an exception in initializers overridden from superclasses that should not be used in the subclass.
Item 17: Implement the description Method
- -(NSString*)description, -(NSString*)debugDescription
Item 18: Prefer Immutable Objects
Item 19: Use Clear and Consistent Naming
- Verbose but clear naming of methods is more acceptable in Objective-C than in other languages.
- Avoid abbreviations, such as str, and instead use full names, such as string.
Item 20: Prefix Private Method Names
- Suggestion: Use "p_" as prefix for private methods.
- Avoid using single "_" as the method prefix, since this is reserved by Apple.
Item 21: Understand the Objective-C Error Model
- Any objects that should be released at the end of a scope in which an exception is thrown will not be released. (-fobjc-arc-exceptions)
Item 22: Understand the NSCopying Protocol
- To support copying:
- Implement NSCopying protocol.
- Override -(id)copyWithZone:(NSZone*)zone or -(id)mutableCopyWithZone:(NSZone*)zone
- If your object has mutable and immutable variants, implement both the NSCopying and NSMutableCopying protocols.
沒有留言:
張貼留言