Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The Accessors pattern (also known as “setters and getters”) describes a technique for funneling all access to an object’s properties through well-defined and easy to recognize methods called accessors. Properties are often stored as instance variables but in some cases may be stored a different way or calculated as needed. The Accessors pattern maximizes implementation flexibility while minimizing opportunities for errors. The Accessors pattern provides the following benefits:
Implementation flexibility. Properties can be stored as instance variables or using other techniques such as the Associative Storage pattern, and the implementation can be changed without breaking other code.
Minimum maintenance burden. All uses of an object’s properties are funneled through a few methods limiting the number of places where code needs to change if properties change.
Simple usage of Cocoa’s reference counted memory management conventions. Restricting memory management to Accessor methods provides the simplest way to adhere to Cocoa’s conventions and isolates memory management code to just a few methods.
Support Cocoa Key Value Coding and Key Value Observing technologies. The Key Value Coding and Key Value Observing technologies won’t work with your classes unless you provide correctly named Accessor methods. Cocoa Bindings (Chapter 32, “Binding and Controllers”) require Key Value Coding and Key Value Observing.
Enable special processing when Outlets connected in Interface Builder are reestablished during .nib loading.