Hi,
In my latest app, I wrote the property setters for some model classes as taking
a different argument type than the type returned by the getters.
I don't feel totally comfortable with that, so I would appreciate some
feedback. Here is what I did and why.
I have a domain class with a number of fields, most of them NSString, but a few
NSDate, int and BOOL, for example
@interface Stuff : NSObject {
NSString *name;
NSDate *when;
int *size;
BOOL *grownUp;
}
@property (nonatomic, readonly) NSString *name;
@property (nonatomic, readonly) NSDate *when;
@property (nonatomic, readonly) int *size;
@property (nonatomic, readonly) BOOL *grownUp;
@end
@implementation
@synthesize name, when, size, grownup;
As you can see at this point, I have the "normal" getters. These objects are
displayed (read only) in a table view, using the column identifier as the key
for KVC. So far, so good. Now I'm going wild defining my setters:
- (void) setName:(DOMNode *)aNode
{
// parse the DOM node to set the name
}
- (void) setWhen:(DOMNode *)aNode { ditto }
- (void) setSize:(DOMNode *)aNode { ditto }
- (void) setGrownUp:(DOMNode *)aNode { ditto }
@end
You might guess why I did that: these objects are created by parsing a DOM
tree, and I dispatch the correct setter using the DOM node "class" using KVC.
Each setter parses its own node "class".
It all works very well.
But I'm not sure I like it very much. Sure it uses KVC quite nicely both for
creating the objects from the DOM tree and for displaying them in the
tableView, but it feels like a kludge. Additionally, if I want to make the
objects editable in the table view, it won't work any more (at least without
testing the class of the setters' argument).
Any comment on this pattern? Any suggestion to make it more "abstraction
compliant"?
Thanks for your attention.
Jean-Denis
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]