Consistency question


#1

Hi,
I have a small question about consistency. On page 284, you implemented the initializer the following way:

- (instancetype)init
{
    return [self initWithProductName:@"Unknown"];
}

In this case you passed the “Unknown” string as a parameter. However on page 288, you did it this way:

- (instancetype)initWithProductName:(NSString *)pn
{
    return [self initWithProductName:pn firstOwnerName:nil];
}

Why, instead of passing the “Unknown” string again, are you using nil? wouldn’t be better for consistency to use “Unknown” (Or “No Name”, or anything else)?

Thanks,

Lucas


#2

Here’s my take:

If you used “Unknown” or similar, as you suggest, you would be adding “Unknown” as the first entry in the NSMutableSet. We haven’t used the NSMutableSet to do much, but it seems like it is used to track the name of the owner as ownership changes and could accept multiple owners (though I don’t know why a Toaster or Washing Machine would need multiple owners, but whatever). There isn’t much benefit to starting out with the first owner being listed as “Unknown”, and then removing that later when an actual owner took ownership. It is better to initialize the NSMutableSet with no entries, e.g. nil.