Fundamental Object-Oriented Concepts

There are only a handful of key concepts that you need to understand to grasp the essence of object-oriented programming. This section presents those key concepts along with Objective-C implementation details, where appropriate.

Objects

An object is a self-contained programmatic unit that combines data and the procedures that operate on that data. An object’s data is kept in instance variables. The functions that affect or make use of the data in an object’s instance variables are known as methods.

Like objects in the physical world, objects in a program have identifying characteristics and behavior. Often, programmatic objects are modeled on real objects. For example, an object such as a button has an analogue in the buttons on control devices, such as stereo equipment and telephones. A button object includes the data and code to generate an appearance on the screen that simulates a “real” button and to respond in a familiar way to user actions.

Encapsulation

Just as procedures compartmentalize code, objects compartmentalize both code and data. This results in data encapsulation, effectively surrounding data with the procedures for manipulating that data. Figure 2.4 shows this relationship between an object’s data and its methods.

An object

Figure 2-4. An object

Though it might look a bit like a jelly doughnut or a slashed tire, this symbol illustrates ...

Get Learning Cocoa now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.