Why Do We Need OOPs?

Why Do We Need OOPs?

OOPs Series In C++

·

3 min read

In this blog, we will cover,

  1. What was the problem with Procedural Programming(POP)?
  2. Why do we need Object Oriented Programming(OOP)?
  3. What actually OOPs is?

Introduction:

Object-Oriented Paradigm was developed because there were some problems with Procedural Paradigms. To understand what OOPs do for us, we first understand what were problems with the Procedural Paradigm due to which OOPs came into being.

Problem With Procedural Paradigm:

A procedural Programme is divided into functions in which each function has a clearly defined purpose. But when projects become complex and complex, schedule slips, more programmers are added, costs skyrocket, and at last, disaster ensues. Analyzing the reasons for such failures reveals that there are some problems with the Procedural paradigm. There were two reasons for such problems.

  • Unrestricted Access
  • Real World Modeling

1: Unrestricted Access:

There are two types of data. Local and global. Local data is only accessed by its function and global data is accessible by all functions of a program. But, when some other functions need access to some local data, it becomes necessary to make that data global data. In large programs, there are many functions and global data items. This leads to a large number of connections between function and data. So, it makes a program difficult to understand and also difficult to modify. If a programmer needs to change a global data item, he must rewrite all the functions that are accessing such data. But it is not an easy task to tell which function access the data. It also causes a function to work improperly with other global items. As everything is related to everything else, modification can sometimes cause a disaster.

2: Real-World Modeling:

In the real world, we deal with objects such as people, buses, etc. Such objects have attributes(height, color) and behavior(how to work). In a programming language, these attributes are called data, and behavior is called functions. So, in order to make a program that is based on the real world, we must consider objects in which data and functions are present at one location. But the problem here is that in procedural programming data and functions are organized separately which does make a poor real-world model.

Object-Oriented Approach:

The basic approach behind OOP is to combine data and functions into a single entity. That entity is called an object. Object’s member functions are the masters here. They provide the only way to access their data. We cannot access and modify the data directly. Because the data is hidden inside. In order to read some data in an object, we have to call a member function of the object. It will provide read access to us. This provides restricted access and high-proof security.

The point to be noted is, OOP is not concerned with details of a program working instead it only deals with program organization.

Conclusion:

Procedural Programming deals with a series of steps to be carried out but Object-Oriented views a program as a group of objects that have certain properties and have certain actions.

Hope you like this blog.

Happy Learning :)