OOP 101 Part I - Why OOP?

At the beginning, when people started doing code, procedural programming was the way to go: one instruction was written after the other. When applications started gaining complexity, and operations became repetitive, programmers started to implement functions that they could reuse and where they could group a set of instructions to be executed that were related to a functionality or a task.

However, this was not enough. Now the code looked like a never-ending list of random functions. And even though the functionalities could be grouped by files, there was a better way to organize it.

Remember programming it's all about modeling the real world and give instructions so detailed that the machine is able to automatize tasks we were doing by ourselves before. Computers, in its original state, are able to compute massive amount of data (faster than a human) but you have to tell them how to do it. They are not able to make decisions or to analyze data by themselves, with the exception of the Artificial Intelligence applications so widely used nowadays, but even those programs had to be taught at the beginning of how to behave and which constraints to include.

Object Oriented Programming (OOP) was designed as a way to model a system, to make it closer to the real life, grouping both data and behavior in a single entity called class. By data we mean variables and by behavior we mean methods. Just to clarify: The functions inside a class we call them methods and the variables commonly receive the name of members (for the latter exists more names but we will use this one).

Think of a class as a template. We can reuse this template as many times as we want. The entities that we create using this template we call them objects, so objects are materializations of a class. In programming we say: an object is an instance of a class.

But take into account that every object can be slightly different (or not) from the other because its members could have different values. For example, I can have the class student, which has as members name, address and date of birth but every object is going to instantiate this class in a different way since the values for the variables can be different.

But what if two objects have the exact same value? Are they the same object? Well, I can print the same book two times but even though they have the same content they are two books, two objects. Every created object normally is located in a different address in memory (take into account this may vary between programming languages and the way they do the memory management).


Other resources

Click on each element on the carousel to access to the content: