Changes

Jump to: navigation, search
Direct Access to Encapsulated Data
== Direct Access to Encapsulated Data ==
Data encapsulation encourages the use of methods to get and set the values of instance variables in a class. Now is probbaly probably the time to point out this is a guideline rather than a rule. in In fact, it quite common for developers to want to directly access an instance variable without having to go through an accessor method. The Objective-C syntax for referencing an instance variable is as follows:
<tt>[''classinstance variablename'']</tt>
Taking our bankAccount BankAccount example, therefore, we could get the value of our accountNumber instance variable and assign it to a variable named ''balance1'' as follows:
<pre>

Navigation menu