Programming in Objective-C: Classes, Objects, and Methods
You need to learn a little bit of terminology, but we keep it fairly informal. We also cover only some of the basic terms here because you can easily get overwhelmed. Refer to Appendix A, “Glossary,” at the end of this book for more precise definitions of these terms.
What Is an Object, Anyway?
An object is a thing. Think about object-oriented programming as a thing and something you want to do to that thing. This is in contrast to a programming language such as C, known as a procedural programming language. In C, you typically think about what you want to do first and then you worry about the objects, almost the opposite of object orientation.
Consider an example from everyday life. Let’s assume that you own a car, which is obviously an object, and one that you own. You don’t have just any car; you have a particular car that was manufactured in a factory, maybe in Detroit, maybe in Japan, or maybe someplace else. Your car has a vehicle identification number (VIN) that uniquely identifies that car here in the United States.
In object-oriented parlance, your particular car is an instance of a car. Continuing with the terminology, car is the name of the class from which this instance was created. So each time a new car is manufactured, a new instance from the class of cars is created, and each instance of the car is referred to as an object.
Your car might be silver, have a black interior, be a convertible or hardtop, and so on. In addition, you perform certain actions with your car. For example, you drive your car, fill it with gas, (hopefully) wash it, take it in for service, and so on. Table 3.1 depicts this.
Table 3.1 Actions on Objects
Object |
What You Do with It |
Your car |
Drive it |
Fill it with gas |
|
Wash it |
|
Service it |
The actions listed in Table 3.1 can be done with your car, and they can be done with other cars as well. For example, your sister drives her car, washes it, fills it with gas, and so on.