OOPS Concepts and its Pillars
0 3260
The process of representing a real-life object in the code or the way of trying to simulate the real-life things in our source code is known as an object-oriented programming language.
The important objects or Pillars of OOPS are Object, Class, Abstraction, Inheritance, Encapsulation.
Object:
It can be any piece of code that represents the real-life entity or in other words, you can say. The process of representing something in the code that represents that user is known as Object that has two things i.e. attribute (characteristics) and functionality (behaviors). It is an instance of the type class
Example:
Book has attributes like color, dimension, and functionality include reading (), writing (), etc.
Class:
The class is known as the specification of the object or in other words, you can say that it is a template to create the specification of an object. We can create a no of the object after creating any class.
Example:
If we are maintaining a system of employees of any organization. The most important object in that is employee itself, we have to identify the attributes of the student his behavior and attributes such as name, id no, and rank, and in behavior, we are storing performance(), project performance(). We have created a class of employees.
In our programming, we map variables into variables or data members whereas function and functionality to function.
Attributes and Behaviors are interrelated; the rank of the employee will modify the performance of the employee. Which means modification in any attribute modifies the Behaviors of the class.
As we already know that int y=9; // the statement means that y is the variable of type int in the similar method, we can say that if we want to create an object of the class
employee e; // we can say that e is the variable of type employee which is a class and e is the object of that class, which will clear that the object is the instance of the specific class.
Abstraction
As we had created the Class employee, has various attributes and data members that can be possible in real life that may be age, weight color, hair color, eating habits, friends, brother, and many more. Since we are creating a database of an organization where hair color, eating habits, friends are not required. Here, the concept of Abstraction will be applied.
The process of selecting a few required attributes from the list is known as the Abstraction i.e. we are taking all the necessary requirements and ignoring the irrelevant.
In a very similar way, we are trying to map different behavior of the employee that may be discipline, punctuality, sportsmanship, leadership, technical skill, writing skill, communication skill and many more may be cross hundreds.
But in our project, there is no need for all the functions of the employee, we are limit to a few things that are relevant to our project.
Abstraction is selecting particular attributes that make relevance to our project.
Very Common Example of Abstraction
Nowadays, API is used in Java and many other built-in functions that are used in c such as scanf, printf, Developer directly calls all the library functions in c and classes in java without any knowledge of the inside code implementation.
This is also an example of abstraction, that we do not have knowledge about the code used in java classes we directly create an object of that class and use it in our program.
ENCAPSULATION
The concept of encapsulation is created from the word "capsule". Why are capsules used if we have normal other medicines? It is made of some chemicals that prone to some atmospheric reaction .capsule provides protection to that chemical.
The principle of encapsulation has been taken from this concept. Every company whether they are small or big MNC requires data security since data act as the most essential community in any software.
In C++, data is protected with encapsulation with the use of access specifier i.e. private, public, and protected. Private Encapsulation has two main roles in C++ programming language i.e controlling data access.
It has functionality and data that are bound together within the class in order to safeguard your system.
Inheritance
In real-world, object, or things found in the form of relationship which needs to be simulated. Boss-employee, parent-child, teacher-student, boyfriend-girlfriend, husband-wife.
Things all around the world work in a relationship. We need both objects and relationships to simulate. This simulation can be done with the help of inheritance.
Share:
Comments
Waiting for your comments