Created
October 10, 2009 01:40
-
-
Save sukima/206496 to your computer and use it in GitHub Desktop.
How to best implement a data model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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