在我的编程课程介绍中,大部分内容都被分成带有注释的部分,如下所示:
@interface ClassA : NSObject
{
@protected
NSMutableArray *_objects
}
/* constructors */
+(id) initWithObjects: (NSMutableArray *) objects;
-(id) initWithObjects: (NSMutableArray *) objects;
/* properties */
@property(nonatomic, strong) NSMutableArray *objects;
/* methods */
- (void) haveFunWithObjects;
我发现这是一种组织事物的有用方式,但很多时候,我需要在一段相当深奥的代码中间加上简短描述的开头或插入文档,然后我对我应该如何做感到困惑记录它:
@interface NDTuple : NSObject
{
@protected
NSMutableArray *_components;
NSUInteger _dim;
}
/* constructors */
/* This constructor initializes the components array to elements all of 0 */
+(id) initToZeroForDim: (NSUInteger) dim;
-(id) initToZeroForDim: (NSUInteger) dim;
+(id) initWithComponents: (NSMutableArray *)components;
-(id) initWithComponents: (NSMutableArray *)components;
/* properties */
@property(nonatomic, strong) NSMutableArray *components;
@property(nonatomic, assign) NSUInteger dim;
/* methods */
- (NDTuple *) minus: (NDTuple *) subTuple;
- (void) replaceComponentAtIndex: (NSUInteger) index withComponent:(id)anObject;
- (id) componentAtIndex:(NSUInteger) index;
也许这不是最好的例子,但我真正要问的是是否有更好的方法将代码拆分为公共部分?