I have noticed this pattern in other areas of Objective-C programming, but this one is such an obvious case I thought I might as well ask.
In the Accessor Methods section on page 43 it talks about the subject of getters and setters, but I find that very unintuitive (I know I have already begun adjusting my frame of mind on the matter) that the getter is listed before the setter.
How is it that you can get something that hasn’t been set yet? It seems that it should setters and getters, in that order. Additionally the code sequence also follows that same reverse logic pattern:
[code]// a getter method
- (NSString *)itemName
// Return a point to the object this BNRItem calls its itemName
// a setter method
- (void)setItemName:(NSString *)newItemName
// Change the instance variable to point to another string,
// this BNRItem will now call this new string its itemName
itemName = newItemName;
And so my question is this: why are the getters listed before the setters, when in reality a value has to be set before it can be got! Does the compiler parse the code “backwards”
As noted above, I am willing to modify my perspective on such things if I understand that logic behind it. Please help me understand.
P.S. By reading further I may have answered my own question as the setters are declared in the interface (.h) file and then set and returned in the implementation file. If this is correct then shouldn’t the example on page 43 have it as setters and getters?