Oct 20, 2024

What is Procedural Oriented Programming (POP) and Object Oriented Programming (OOP)?

Procedural Oriented Programming (POP) and Object Oriented Programming (OOP) are two fundamental programming paradigms. Here's a brief overview of each, along with examples in JavaScript:

 

Procedural Oriented Programming (POP)

POP is a programming paradigm based on the concept of procedure calls, where the program is divided into small parts called functions or procedures. It focuses on a sequence of actions to be performed.

 

Characteristics:

  • Emphasis on functions.
  • Functions operate on data.
  • Data is typically passed between functions.
  • Code is organized into procedures or routines.
  • Easier to understand for small programs but can become complex for larger applications.

 

Example in JavaScript:

// Procedural approach to calculate the area of a rectangle
function calculateArea(length, width) {
    return length * width;
}

let length = 5;
let width = 3;
let area = calculateArea(length, width);
console.log("Area of the rectangle:", area);

 

Object Oriented Programming (OOP)

OOP is a programming paradigm based on the concept of "objects", which can contain data in the form of fields (often known as attributes or properties), and code in the form of procedures (often known as methods).

 

Characteristics:

  • Emphasis on objects.
  • Objects are instances of classes.
  • Encapsulation: Bundling data and methods that operate on the data within one unit (class).
  • Inheritance: Mechanism to create a new class using properties and methods of an existing class.
  • Polymorphism: Ability to process objects differently based on their data type or class.
  • Abstraction: Hiding complex implementation details and showing only the necessary features.

 

Example in JavaScript:

// Object-Oriented approach to calculate the area of a rectangle
class Rectangle {
    constructor(length, width) {
        this.length = length;
        this.width = width;
    }

    calculateArea() {
        return this.length * this.width;
    }
}

let myRectangle = new Rectangle(5, 3);
let area = myRectangle.calculateArea();
console.log("Area of the rectangle:", area);

 

Key Differences:

  • Structure: POP is function-based, while OOP is object-based.
  • Data Handling: In POP, data is passed between functions, whereas in OOP, data and methods are encapsulated within objects.
  • Reusability: OOP promotes code reusability through inheritance and polymorphism, while POP relies on function reuse.
  • Complexity Management: OOP is better suited for managing complex applications due to its modular approach, while POP can become unwieldy as the program size grows.

 

The list of POP and 00P programming languages

Procedural-Oriented Programming (POP) Languages:

  1. C
  2. Pascal
  3. Fortran
  4. BASIC
  5. COBOL
  6. Ada
  7. ALGOL
  8. MATLAB (supports procedural programming)
  9. Perl (supports procedural programming)
  10. Shell scripting languages (e.g., Bash)

 

Object-Oriented Programming (OOP) Languages

  1. Java
  2. C++
  3. Python
  4. C#
  5. Ruby
  6. Swift
  7. Objective-C
  8. PHP
  9. JavaScript
  10. Kotlin

 

NOTE THAT some languages, like Python and JavaScript, support multiple paradigms including both OOP and POP.