Object Oriented Programming (OOP) is a programming model which is based on objects and classes. In Procedural programming programmer focus on tasks instead of objects but in OOP programmer focus is more on objects rather than tasks. In this article we are going look at some of the Basic Concepts and Features of Object Oriented Programming.
Basic OOP concepts with Real Life Examples:
Before going further let me describe what is the difference b/w Object Oriented approach and Task Oriented approach.
In object oriented approach we are concerned with the object who is doing the work whereas in task oriented approach we are concerned with what is being done.
To understand the difference b/w task oriented and object oriented let considered a scenario.
Suppose you watched a movie and one of your friend asked you tell to him the story of the movie. Now you have two options to describe the whole story of the movie. The first way is that you will tell him the complete story of the movie scene by scene. The other option would be that you will give him a brief summary about what happened in the movie.
Now think any movie and consider the whole scenario as described above. You will find that the second option to describe the story of a will be better than telling the whole story scene by scene as telling him the summary of movie will take less time and your friend understand better. Basically, what is happening here is that when you are telling movie story scene by scene means you are telling every act happened in the movie. So we can say that you are focusing on movie story, In other words you are focusing on what is happening in the movie(task oriented approach).On the other hand when you are describing whole movie story as a summary , you will see that your focus will shift to the characters of the movie. This is the Object Oriented approach.
Naturally, human has a object oriented approach means he focus on objects rather than tasks. Consider doing the whole scenario describe above with your friend to understand better.
Features of Object Oriented Programming:
Now let’s look at the features of OOP one by one.
It is the one of the most important and main feature of OOP ,without objects OOP is nothing. Any real world objects you see in your daily life will have some attributes and methods .Let say, a car has some attributes (properties) , like it has wheels, doors, engine etc. These all are the attributes of the car. Similarly car do different tasks like we can apply brakes, increase speed of its etc. These all are the methods of car. Similarly in OOP, we say that a object consists of well define attributes and methods.
As said above objects have attributes and methods, but where to keep these methods and attributes of objects? The answer is class is the place where we keep object related methods and attributes.
Ok so we created class for object so it means we have to create class for every object? No, this is not the right approach. Basically if there are multiple objects with same methods and attributes then they will have a same class. So we will have to create only one class for multiple objects whose attributes and methods are same. But if there are different objects whose attributes and methods are complexly different then clearly we will create separate class for that.
Poly means many and morphism means many forms so after combining these two words it becomes many forms. In OOP, there are many situations occurred when you want to use same thing but in different form.
Suppose you create a function named sum which will add two numbers. Now , you want to use this same function but instead of adding two numbers you want to add three numbers so what to do? The answer is that you will use that same function but now it will add three number instead of two.This is the kind of overloading which is the part of Polymorphism.
Polymorphosim consist of two main concepts which Overloading and Overriding. Overloading means doing same work but in different forms using the same object where as overriding means doing same work in different form using different objects. You will learn these concepts better when you will go deep in Polymorphosim.
In simple words,Abstraction means focusing on information rather than implementation. It is the process of hiding the implementation of certain function.The user only know what what the object do
instead of how it it being done.
Suppose a real life example that to turn on an Air Conditioner, you only press the on button .You only know how to turn on A.C using button .You don’t how it is turned on .In other words you don’t know its functionality.
As a capsule protect the medicine inside it from outside world. Similarly we use the concept of Encapsulation to protect our data from outside the world.It is done by restricting our data by using different ace specifiers which describes who can access the data.
One of the most important thing in Features of Object Oriented Programming is that they all represent real wold behavior and because of this Object Oriented Programming is so organized and secure which makes it better than procedural programming.
Sharing is caring and don't forget to subscribe to get more tutorials like this directly in your inbox !