Basic concepts of OOP!

Fazal
3 min readFeb 26, 2022

Hey buddy, It’s been a long since I blogged and I wrote this cool blog in a selfish to make me understand the OOP concepts and I hope you too will get an idea from it. Let’s start by understanding what is OOP.

What Is Object-Oriented Programming (OOP)?

Object-oriented programming is a way of programming that enables programmers to think like they are working with real-life entities_(a thing with distinct and independent existence)_ or objects. In real life, people have the knowledge and can do various works. In OOP, objects have fields to store knowledge/state/data and can do various work — methods.

Object:

It’s the instance of a class/ it’s the working entity of a class.

Class:

It is a template or blueprint about the capability of what an object can do.

Method:

The behaviors of a class. It tells what a method can do.

Instance:

Object and Instance both are the same with a small difference. Objects are things in memory while instances are things that reference to them
The creation of an instance is called instantiation!

Instance != Instance Variable:

Instance variables belong to an instance of a class. Another way of saying that is instance variables belong to an object since an object is an instance of a class. Every object has its own copy of the instance variables.

OOP’s Concepts:
1. Abstraction
2. Encapsulation
3. Polymorphism
4. Inheritance

Abstraction:

Abstraction allows us to expose limited data and functionality of objects publicly and hide the actual implementation. It is the most important pillar in OOPS. In our example of Mobile class and objects like Nokia, Samsung, iPhone.

For example,
Let’s take switchboard, in general, we click the switch as per our requirement. You need not know the internal working of these switches. What is happening inside is hidden from you.

This is abstraction, where you only know the essential things to operate on a switchboard without knowing the background details of the switchboard.

In simple words, Abstraction refers to the act of representing essential features without including the background details.

Encapsulation:

Encapsulation is defined as the process of enclosing one or more details from the outside world through access rights. It says how much access should be given to particular details. Both Abstraction & Encapsulation works hand in hand because Abstraction says what details are to be made visible and Encapsulation provides the level of access right to that visible details. i.e. — It implements the desired level of abstraction.

Talking about Bluetooth which we usually have on our mobile. When we switch on Bluetooth, I am able to connect to other mobile or Bluetooth-enabled devices but I’m not able to access the other mobile features like dialing a number, accessing inbox, etc. This is because the Bluetooth feature is given some level of abstraction.

Another point is when mobile A is connected with mobile B via Bluetooth whereas mobile B is already connected to mobile C then A is not allowed to connect C via B. This is because of accessibility restrictions.

In simple words, Encapsulation is Wrapping up data and functions into a single unit.

Polymorphism:

polymorphism (from the Greek meaning “having multiple forms”) is the characteristic of being able to assign a different meaning or usage to something in different contexts — specifically, to allow an entity such as a function, or an object to have more than one form.
For example,
Like a man at the same time is a father, a husband, an employee. So the same person possesses different behavior in different situations. This is called polymorphism

Inheritance:

Inheritance is the procedure in which one class inherits the attributes and methods of another class. The class whose properties and methods are inherited is known as the Parent class.

For instance, we are humans. We inherit certain properties from the class ‘Human’ such as the ability to speak, breathe, eat, drink, etc.
For example,
Let’s take child and parents, all the properties of the father are inherited by his son.

I guess I covered the major Topics, Sorry for the grammar mistakes I made in this blog hope you like it.

Cheers…!

https://www.instagram.com/__fazalurrahman__/

--

--

Fazal

Security Analyst | Bug Hunter | google VRP researcher | Developer