Do you know where 4 oops concepts are used in your code?

Object Oriented Programming is a very important concept and is a popular way to manage your project code. Most of the new programmers remember the theoretical part of OOP but can’t relate all the important concepts in real programming. This article is about those programmers who don’t understand OOP in their code.

I am not going to explain the definition but will try to explore more of a practical view of all 4 key pillars of Object Oriented Programming. After reading this you will be able to understand where each concept is used in your OOP code. Let’s start explaining one by one

1. Encapsulation:

Encapsulation is the process of data hiding. So if you have a class then how would you hide its properties and methods? It is very simple by using access modifiers like Private, Protected and Public. Therefore, controlling the visibility or accessibility in class is called encapsulation. You are using this concept in almost all your OOP code but did not have clear understanding where it is used in your code.

2. Abstraction:

Data abstraction is the process of exposing only necessary things to end user. In your code where you fetch specific class members and not all members? It is also very simple, you create object of class and fetch specific method or property. This process is called Abstraction. This is also a concept you cannot ignore your daily programming but did not know where the abstraction is and where is the encapsulation.

3. Inheritance:

This is the concept of deriving a class into another class to use other class properties. I believe everyone understand this concept practically and should not have any confusion. Just to remind you Protected keyword which is used to encapsulate the members is used in case of inheritance. There is a slight difference between private and protected, Both can’t be accessed outside their class but protected can be accessed inside child class and private member can’t be accessed.

4. Polymorphism:

Polymorphism is the concept of using same name for multiple class members. For example you can have 2 methods with the same name but with different parameters. It is further divided in 2 parts, when we use same name for multiple members within a single class then it is called overloading and when we use same name for multiple members across parent and child class then it is called overriding.

I believe after reading the above explanation you will be have clear connect between the theoretical Object Oriented Programming and practical code. Next time someone asked you the practical aspect of this famous concept, you can shoot the impression by explaining it clearly. I hope you all like it. Click here to know what concepts you should know as a software engineer

Category: