Actually i’m starting objective c from scratch with this book. i reached 22 and came to example.
when i move OfficeAlarmCode to class extension, book says that it has a two effects and first is:
But “mikey” is a BNREmployee object, so it can access officeAlarmCode. compiler returns error. why?
Actually i’m starting objective c from scratch with this book. i reached 22 and came to example.
when i move OfficeAlarmCode to class extension, book says that it has a two effects and first is:
But “mikey” is a BNREmployee object, so it can access officeAlarmCode. compiler returns error. why? [/quote]
That (underlined) statement is very confusing; it implies that objects that are instances of BNREmployee can access that property from anywhere:
...
BNREmployee *mikey = [[BNREmployee alloc] init];
unsigned int mikeysCode = mikey.officeAlarmCode;
...
because mikey is an instance of BNREmployee and should be able to see its own office alarm code.
The statement should have expressed where the property can be seen, instead of the object instances seeing the property.
There won’t be any confusion, if we rewrite that statement as “This property can no longer be seen from outside the methods of BNREmployee class.”
Access from outside BNREmployee methods is not possible:
int main ()
{
...
BNREmployee *mikey = [[BNREmployee alloc] init];
unsigned int mikeysCode = mikey.officeAlarmCode;
...
}
Trying to explain things using OO lingo can sometimes produce confusing results. I hope that, in trying to clear it up, I haven’t caused more confusion.
Thanks for your comprehensive answer. now it cleared for me.
[quote=“ibex10”][quote=“miximixi”]Hello there,
Actually i’m starting objective c from scratch with this book. i reached 22 and came to example.
when i move OfficeAlarmCode to class extension, book says that it has a two effects and first is:
But “mikey” is a BNREmployee object, so it can access officeAlarmCode. compiler returns error. why? [/quote]
That (underlined) statement is very confusing; it implies that objects that are instances of BNREmployee can access that property from anywhere:
...
BNREmployee *mikey = [[BNREmployee alloc] init];
unsigned int mikeysCode = mikey.officeAlarmCode;
...
because mikey is an instance of BNREmployee and should be able to see its own office alarm code.
The statement should have expressed where the property can be seen, instead of the object instances seeing the property.
There won’t be any confusion, if we rewrite that statement as “This property can no longer be seen from outside the methods of BNREmployee class.”
Access from outside BNREmployee methods is not possible:
int main ()
{
...
BNREmployee *mikey = [[BNREmployee alloc] init];
unsigned int mikeysCode = mikey.officeAlarmCode;
...
}
Trying to explain things using OO lingo can sometimes produce confusing results. I hope that, in trying to clear it up, I haven’t caused more confusion.[/quote]