Integrating the object-oriented mindset
Things in the physical world operate on a similar level to OOP; when you want to buy a soft drink, you grab a can of soda, not the liquid itself. The can is an object, grouping related information and actions together in a self-contained package. However, there are rules when dealing with objects, both in programming and the grocery store—for instance, who can access them. Different variations and generic actions all play into the nature of the objects all around us.
In programming terms, these rules are the main tenets of OOP: encapsulation, inheritance, and polymorphism.
Encapsulation
One of the best things about OOP is that it supports encapsulation—defining how accessible an object's variables and methods are to outside code (this is sometimes referred to as calling code). Take our soda can as an example—in a vending machine, the possible interactions are limited. Since the machine is locked, not just anyone can come...