Basic concepts of OOP

Object Oriented Paradigm is based on some concepts that help us overcome the disadvantages of the traditional procedural programming paradigm.
Let’s look at these concepts

Data Abstraction

It is the art hiding complexities and represent just the essential features of something.
It is the concept of simplifying real world concept into essential features.
Let’s see an example, when we ride a bike we are only given certain controls like accelerator, brake, clutch, etc. to control the complete bike.
But many complexities are hidden from us that we don’t care about like wiring, motor working etc.
This is data abstraction.
Programs are designed in such a way that complexities are hidden from the end user and he/she is given only certain simple controls or GUI to operate that program.

Data Encapsulation

The wrapping up of data and the functions that operate on that data into a single unit called class.
This is the most important concept of OOP and is known as data encapsulation.
Certain kinds of data is not be accessed by everyone from the outside so they are hidden behind function (or methods) that operate on them and accesses the data.
Let’s look at an example.
Suppose there is a university with different kinds of departments like Math, Physics, Computer science, Arts, etc.
Now a teacher of CS department wants to know the number of failed students in Math department.
But the CS teacher will not be allowed to himself go through grade sheet of Math department and check the results.
Rather he will ask a teacher of Math department his query and then the teacher of Math department goes through the grade sheet of Math department and passes on the result.
An access level is maintained across departments which is very important for data security so that anyone from outside cannot change/access data.
And all these things are handled under one roof, class.

Inheritance

Inheritance is the property of one class to inherit features of another class.
Here inherit means to reuse the features of the class it inherited from without redefining those features.
One of the major advantages of inheritance is code reusability.
Suppose there is a class Person which has features like hands, legs, ability to walk, ability to speak, etc.
Now we defined a class Male which inherits Person class.
Now it can access these features of the Person class without defining them again and also it contains additional features of its own like Adam’s apple, thick facial hair, etc.
We reused the features without defining them again explicitly.
A point to note here is that as Male class inherits Person class.
So basic terminology says that Male is subclass of Person and Person is base class of Male.

Polymorphism

The ability of data to be processed in many different forms is called polymorphism.
It is the most important concept of OOP.
Basic Examples of OOP are
1. Function overloading: A function with same name can behave in many different forms
2. Operator Overloading: ‘*’ operator can both be multiply operator and dereference operator depending on number and type of operands.
Similarly, ‘+’ can both be addition and string concatenation.

AUTHOR

READ NEXT

Boostlog is an online community for developers
who want to share ideas and grow each other.

Delete an article

Deleted articles are gone forever. Are you sure?