Skip to main content

Difference Between POP and OOP

 

What is the Difference Between POP and OOP?

Procedure-Oriented Programming (POP) and Object-Oriented Programming (OOP) are two fundamental programming paradigms. Both have their own methodologies, approaches, and use cases. Below, we will define both paradigms, outline their key differences, and provide examples of each for better understanding.

 

Definition of POP (Procedure-Oriented Programming)

Procedure-Oriented Programming (POP) is a programming paradigm where programs are designed around procedures or functions. It focuses on dividing the program into smaller units called functions, which operate on data.

Key Features of POP:

  1. Program is divided into functions or procedures.
  2. Functions are the main building blocks of the program.
  3. Emphasizes a step-by-step procedural approach.
  4. Data and functions are separate, with functions manipulating data.

 

Definition of OOP (Object-Oriented Programming)

Object-Oriented Programming (OOP) is a programming paradigm that organizes software design around objects, which are instances of classes. These objects combine data (attributes) and functions (methods).

Key Features of OOP:

  1. Program is divided into objects and classes.
  2. Objects represent real-world entities.
  3. Emphasizes reusability through concepts like inheritance, polymorphism, and encapsulation.
  4. Data and methods are bundled together in objects.

 

Differences Between POP and OOP

Aspect

POP
(Procedure-Oriented Programming)

OOP
(Object-Oriented Programming)

Program Structure

Based on procedures or functions.

Based on objects and classes.

Focus

Focuses on functions (procedures).

Focuses on data and objects.

Data Handling

Data is exposed to all functions in the program.

Data is encapsulated within objects.

Modularity

Functions are used to achieve modularity.

Classes and objects provide modularity.

Real-World Mapping

Does not map well to real-world entities.

Represents real-world entities as objects.

Code Reusability

Limited reusability; functions are reused.

High reusability through inheritance.

Security

Less secure; no data hiding mechanism.

More secure; supports encapsulation.

Complexity Management

Suitable for smaller programs.

Suitable for large and complex programs.

Example Languages

C, Pascal, Fortran, etc.

C++, Java, Python, etc.

 

Example of POP

Example of OOP

#include <iostream>

using namespace std;

 

float calculateArea(float length, float breadth) {

    return length * breadth;

}

 

void displayArea(float area) {

    cout << "The area of the rectangle is: " << area << endl;

}

 

int main() {

    float length, breadth, area;

    cout << "Enter the length of the rectangle: ";

    cin >> length;

    cout << "Enter the breadth of the rectangle: ";

    cin >> breadth;

 

    area = calculateArea(length, breadth);

    displayArea(area);

 

    return 0;

}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Characteristics of the Example:

  1. The program is divided into procedures (calculateArea and displayArea).
  2. Data (length, breadth, area) is manipulated by these procedures.
  3. No concept of objects or classes is used.

 


#include <iostream>

using namespace std;

 

class Rectangle {

private:

    float length, breadth;

 

public:

    void setDimensions(float l, float b) {

        length = l;

        breadth = b;

    }

 

    float calculateArea() {

        return length * breadth;

    }

 

    void displayArea() {

        cout << "The area of the rectangle is: " << calculateArea() << endl;

    }

};

 

int main() {

    Rectangle rect;

    float length, breadth;

 

    cout << "Enter the length of the rectangle: ";

    cin >> length;

    cout << "Enter the breadth of the rectangle: ";

    cin >> breadth;

 

    rect.setDimensions(length, breadth);

    rect.displayArea();

 

    return 0;

}


Characteristics of the Example:

  1. The program revolves around the Rectangle class and its object.
  2. Data (length, breadth) and methods (setDimensions, calculateArea, displayArea) are encapsulated within the class.
  3. Real-world entity (Rectangle) is directly represented by the object.

 

 

 

 

 

 

 

 

 

#Happy Coding & Keep Learning

Comments

Popular posts from this blog

C++ Lec-2 Introduction to Object-Oriented Programming (OOP) in C++

  Introduction to Object-Oriented Programming (OOP) in C++ Object-Oriented Programming (OOP) is a programming paradigm that uses objects and classes to organize software design. It allows for modelling real-world entities and relationships in a program. C++ is an object-oriented programming language that provides features to implement OOP concepts effectively. Key Concepts of OOP   Class and Object o    Class : A blueprint for creating objects. It defines properties and behaviours of objects.   class Car { public:     string brand;     string model;     int year; };   o    Object : An instance of a class.   Car car1; car1.brand = "Mahindra"; car1.model = "THAR"; car1.year = 2024;   Encapsulation o    Encapsulation is the bundling of data and methods that operate on that data within a single unit, or class. It restricts direct acces...

C++ Lec-1 (Introduction to Programming Languages)

  Introduction to Programming Languages ________________________________________________________________________ P rogramming languages are formal languages comprising a set of instructions that produce various kinds of output. They are used in computer programming to implement algorithms and control the behavior of machines. Language Generation Programming languages have evolved through several generations: First Generation (1GL) : Machine language, the most basic level of programming languages, consisting of binary code. Second Generation (2GL) : Assembly language, a low-level language with a strong correspondence to the machine language instructions. Third Generation (3GL) : High-level languages like C, C++, Java, Python, which are more abstract and easier for humans to understand. Fourth Generation (4GL) : Languages closer to human language, often used for database querying and report generation (e.g., ...

DATA TYPE in C/C++

  BUILT IN OF PRIMARY DATA TYPE     int (Integer) float(Floating-point) double (Double Floating-point) char (Character) wchar_t (Wide Character) bool (Boolean) void (Empty) Modified Data Types List    signed int - (used for integers) unsigned - int (can only store positive integers) short (used - for small integers (range -32768 to 32767)) unsigned short - (used for small positive integers (range 0 to 65,535)) Long - (used for large integers) unsigned long - (used for large positive integers ) long long - (used for very large integers) unsigned long long - (used for very large positive integers) long double - (used for large floating-point numbers) signed char - (used for characters (guaranteed range -127 to 127)) unsigned char - (used for characters (range 0 to 255)) Derived Type Data Type    Function Array Pointers References User-Defined Data Type   Class Structure Union Enumeration Typedef defined DataType