Re-usable Obj-C classes with custom values: The right way

Posted by Prairiedogg on Stack Overflow See other posts from Stack Overflow or by Prairiedogg
Published on 2010-04-16T05:37:27Z Indexed on 2010/04/16 5:43 UTC
Read the original article Hit count: 184

I'm trying to reuse a group of Obj-C clases between iPhone applications. The values that differ from app to app have been isolated and I'm trying to figure out the best way to apply these custom values to the classes on an app-to-app basis.

Should I hold them in code?

// I might have 10 customizable values for each class, that's a long signature!
CarController *controller = [[CarController alloc] initWithFontName:@"Vroom" engine:@"Diesel" color:@"Red" number:11];

Should I store them in a big settings.plist?

// Wasteful!  I sometimes only use 2-3 of 50 settings!
AllMyAppSettings *settings = [[AllMyAppSettings alloc] initFromDisk:@"settings.plist"];
MyCustomController *controller = [[MyCustomController alloc] initWithSettings:settings];
[settings release];

Should I have little, optional n_settings.plists for each class?

// Sometimes I customize
CarControllerSettings *carSettings = [[CarControllerSettings alloc] initFromDisk:@"car_settings.plist"];
CarController *controller = [[CarController alloc] initWithSettings:carSettings];
[carSettings release];

// Sometimes I don't, and CarController falls back to internally stored, reasonable defaults.
CarController *controller = [[CarController alloc] initWithSettings:nil];

Or is there an OO solution that I'm not thinking of at all that would be better?

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about object-oriented-design