Always returning id as type


#1

I have a question concerning the books instruction to always have the return value of an init be type id. There is a statement having to do with subclassing that follows and indicates that not returning id could lead to subclassing errors. I was not following the reason – it stated that the subclass would inherit all of the methods including the init method. Then said …“An instance of the subclass could then be sent this initializer message, but what would be returned? Not a BNRItem, but an instance of the subclass. You might think, “No problem. Override the initializer in the subclass to change the return type … But in Objective-C, you cannot have two methods with the same selector and different return types (or arguments). By specifying that an initialization method returns “any object,” we never have to worry what happens with a subclass.”

I am not following this logic and wondered if someone would be willing to expound upon it. Why is it returned an instance of the subclass and not the BNRItem?

Thanks,
Jwe