Object-Oriented Programming Explained

Byabasaija Pascal
3 min readDec 17, 2021

What is object-oriented programming that you hear every programmer talking about? Why do they care about it anyway? Let’s open our minds.

Photo by Amol Tyagi on Unsplash

So you have heard many software engineers talk about OOP, maybe your tutor or even you have come across many articles written about it but still can’t connect the dots… Just keep reading, you won’t regret it. I promise.

In this article, we are going to focus on understanding, rather than definitions. If you want to check out a more formal definition you can find it here.

Understanding…

When I was learning the English language, I was told that in order to understand a sentence and its full meaning, I needed to break it down, pick out the main words, look them up in the dictionary for different meanings, find the contextual meaning and rebuild the sentence. That way I was able to learn English, and I have been using that technique my entire life to learn new concepts(…ssh! that’s a little bit of a secret!). So how do I apply this in OOP? Just read on.…

Object-Oriented as it sounds, organizes software design around objects. Objects in the world of programming are known to be data fields that have unique attributes and behavior.

In OOP, we focus on objects that we want to manipulate first, then build the logic to manipulate them. Here is an example, say you want to build a house. We don’t expect you to start buying material before you make a plan for your house. You need to make a plan, know the attributes or features that your house needs to have and then start implementing the logic, which is actual building in this case. Ok, that was a little bit wordy, but I just want you to understand.

The structure of OOP.

We are going to continue with our example of a house to furthermore understand the structure of an object oriented program.

  1. Classes - At the very top level of an OOP, we have a class. Say you are building your house, you cannot by building partitions/rooms without building the main walls right? Thats the same thing here. A class acts as a blueprint for individual objects, attributes and methods.
  2. Objects- Alright, now its time to talk about the rooms in our house, and these are instances of our main building. So back to programming, an object is an instance of a class, as simple as that.
  3. Methods- We all know that our house might need some additional things in order to be perfectly habitable. Things like electric power, water, name them. In programing, these are like functions or the blocks of code that describe the behavior of our objects. So if a room is to have lights, it must be connected to power.
  4. Attributes- So we have the main building, we have rooms, we have power connected. So how do we light up a room actually? We need lamps right? So let those be our attributes. They represent the state of our objects and objects will have data stored in the attributes field.

As you can see, the structure is pretty simple to digest. All things are connected, and if an object wants to use methods or attributes, they are just a call away. But wait,

What if there is something we need in our house but we forgot to include it on the plan, do we destroy everything and rebuild? NO. You heard me.

So what do we do?

Go borrow from the neigbour who has.

How do we do that?

We shall see how to do that in the next article…..

Bye for now and thanks for reading

Happy coding!

--

--

Byabasaija Pascal

Full-stack web developer | Ruby | Rails | JavaScript | HTML CSS | Bootstrap.