Object-oriented programming
It makes perfect sense to put all that car-driving and car-loading code together some place, along with some variables to track the gas in the tank, the number of passengers, and so on.
Thus, we extend the concept of imperative programming to object-oriented programming. The lines of code are grouped together into methods of each object, the variables are now properties of an object, and we can write blueprints for each type of object, called classes.
Object-oriented programming, often abbreviated to OOP, is strongly associated with the concepts of mutable data, classes inheriting code from other classes, and message passing between objects. There is also a strong preference for encapsulation, the idea that an object is responsible for its own state (its property values) and internal functionality, and provides an interface to the outside world through which properties and methods can be accessed.
When considering the most modern practices around programming with Cocoa, we need to look briefly at two sub-paradigms (if such a word exists) of OOP:
- Class-based programming
- Protocol-oriented programming