Question:Why Class Extension is needed


In the book, the author writes the following:

[quote]For example, the officeAlarmCode property of BNREmployee should be private. The employee object needs to be able to access its alarm code, while
non-employee objects do not need access to the alarm code and should not have it.[/quote]
As far as I concern, even the officeAlarmCode property is non-private, instances of other class types still unable to access it, right?
Then why do we need the class extension in the first place?

Well hope anyone of you who are expertise enough in this matter to advise me.

Thank you.

If you declare a property in the header file, then any other object can access that property of your object. The header file is like an advertising space, telling all other objects what properties your object has.

If you instead declare the property in a class extension in the .m file, only your object knows that the property exists; it is private and only your object can use it.

Hello Mikey,

Now I know why we need class extension after going through your example!
All of your examples are so good in demonstrating the hard concepts in layman’s term.
Really helpful!


I also agree! :wink: