Object Oriented ProgrammingA graphical representation of how OOP can contrast Procedural Programming
OOP as you are aware relies on classes, from which we instantiate objects. These objects are the reason why we refer to this programming paradigm as Object Oriented Programming, and emphasize the “Object” part. We have already been using classes that are a part of Processing's API such as PImage from which we have instantiated object variables which we have given names, and those objects have inherited various properties and functions (called methods in OOP) from the classes from which they where instantiated. But what exactly is a class?
The concept of a class
A class is simply a body of code that, in a similar way to a function, exists independently of the main body of code from which it is referenced. However, a class does not only have a singular purpose like a function that checks the position of the mouse, or moves and image around in a specific way or has some other purpose that can be summarized by a singularly specific directive. A class can consist of many functions, which in the context of OOP we refer to as methods. These methods can be used like functions of your main program but with the inherited properties of the class from which it came. As a result you can think of a method as being a function of a class, that when used in your main program will, like a function, have a definition independent of the main program and also have properties that are specific to the class it was instantiated from. The benefit of this is that when multiple objects are instantiated from a single class they all inherit the methods of that class, this allows you to use certain methods with one object and certain other methods with another object. Thereby creating relationships between those objects (and ultimately the data you are representing with you main program) with other data or API features in ways that would be very difficult or maybe not practically possible without OOP.