Skip to content

Instantly share code, notes, and snippets.

@sukima
Created October 10, 2009 01:40
Show Gist options
  • Save sukima/206496 to your computer and use it in GitHub Desktop.
Save sukima/206496 to your computer and use it in GitHub Desktop.
How to best implement a data model
// Expose the internal data store. (Easiest but seems error prone)
@interface UserListModalExposeData : NSObject {
NSMutableArray *userList;
}
@property (nonatomic, retain) NSMutableArray *userList;
- (void) someAdditionalMethod;
@end
// Attempt to encapsulate NSArray. (Good but a hassle and seems redundent)
@interface UserListModalEncapsulate : NSObject {
NSMutableArray *userList;
}
- (id) init;
- (id) initWithContents:(NSArray *)data;
- (id) setData:(NSArray *) data;
- (void) addObject:(id)object;
- (id) removeObjectAtIndex:(int)index;
- (id) objectAtIndex:(int)index;
- (int) count;
- (void) someAdditionalMethod;
@end
// Attempt to subclass - Will Fail. NSArray is a cluster. Subclassing is bad (read: confusing)
@interface UserListModalSubClass : NSMutableArray {
}
- (void) someAdditionalMethod;
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment