O'Reilly logo

Programming in Objective-C, Sixth Edition by Stephen G. Kochan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Accessing Instance Variables and Data Encapsulation

You’ve seen how the methods that deal with fractions can access the two instance variables numerator and denominator directly by name. In fact, an instance method can always directly access its instance variables. A class method can’t, however, because it’s dealing only with the class itself, not with any instances of the class. (Think about that for a second.) But what if you wanted to access your instance variables from someplace else (for example, from inside your main routine)? You can’t do that directly because they are hidden. The fact that they are hidden from you is a key concept called data encapsulation. It enables someone writing class definitions to extend and modify the class definitions, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required