Start a personal dev blog on your domain for free with Hashnode and grow your readership.
Get Started

A therapeutic approach to OOP(Object-oriented programming) - part 1

unnamed.jpg Sometimes, people tend to get sick or discouraged when they hear of OOP and I am even guilty of this as well. I remember when I started Android development using Java, doing the UI aspect wasn't a problem but when it came to the functionality of the app, I find myself struggling and my boss told me to go back and understand object oriented programming. As you advance in programming, you will notice that those OOP is a building block for you and when you don't understand it you tend to hook. Object-oriented programming is nothing really to be scared of! Let us look at it from a practical point of view, take a minute and look around you, what do you see? I am sure you will definitely see things like your tables, chairs, cars, trees, computers, phones, etc. if I should leave you, you will probably have more things to add to your list LOL. So the basic idea of this exercise is that all these things you see around you are objects and are real-life entities. These objects have their state and behavior, for example, the state of your phone will be phone name, type of phone, the color of the phone, etc and while the behavior will be calls, send messages, pictures, etc. You can do a little exercise as well and list the state and behavior of the objects around you.

Now, looking at it from a software point of view these states and behaviors of our real-life objects, are basically fields and methods when you are writing code. In that case, we can say that Object-oriented programming(popularly known as OOP) is just about bringing these real-life objects into programming. When you are coding you are trying to solve a real-life problem and this is why OOP is important. Let's go practical again, assuming you want to write a code for an ATM machine you will need fields like the Account name, account number, bank name, balance, etc then they are also capable of performing actions known as methods like withdraw amount, account balance, etc. I am sure you can relate this to some codes you have seen or written? Almost all modern programming languages are object-oriented programming, e.g Java, python, C#, C++, Ruby, JavaScript, etc but I will be focusing only on Java in this article.

The basic concept of OOPs is to create objects, re-use them throughout the program, and manipulate these objects to get results. The OOPs work with the concept of:


1) Classes

A class is a blueprint that describes what the object should look like. In a class you list all the fields, then the implementations.

2) Constructors

Constructors are special methods, you can create an object and initialize it in a constructor.

3) Object

An object is an actual entity that is created from that class.

4) Encapsulation

This deals with hiding details from users. For example, when data is hidden it can only be accessed within that class and cant be accessed by other classes.

5) Polymorphism

It's the ability of a variable, object to take different forms. For example, the word "run" when used with human, laptop, business, it means different things so the same applies to our program.

6) Inheritance

This is when an object takes the properties of the parent class. You can relate it also to us humans when we inherit some things from our parents such as height, complexion, etc so the same case applies here.

There is more OOPs concept like association, aggregation, abstraction but I will only be discussing the ones I listed above. OOP is not something you rush, you have to take your time to understand it and so now we have understood what OOP itself means, in my incoming articles, later on, I will be explaining each of the concepts I listed above weekly in details. So watch out for my articles on OOP. If you have any question don't hesitate to reach out and I will be happy to answer your questions.

Start a personal dev blog on your domain for free and grow your readership.

3.4K+ developers have started their personal blogs on Hashnode in the last one month.

Write in Markdown · Publish articles on custom domain · Gain readership on day zero · Automatic GitHub backup and more

hallyG's photo

Very nice one..wehdone vikky

Vito Scarletta's photo

Nice one

mayaki ujeh's photo

Nice writeup, this is really helpful. Atleast people dont get to be scared of OOP anymore with such explanation.


Oladele David Temidayo's photo

This is wonderful and i learnt a whole lot. came here from the Dev Group, and i must say this is a great content Opene Victoria