fbpx

Procedural Programming and Object Oriented Programming

Object Oriented Programming

INTRODUCTION

Programming evolves through different paradigms, with Procedural Programming (PP) and Object-Oriented Programming (OOP) being two prominent approaches. PP focuses on organizing tasks into functions, such as int add(int a, int b), to perform specific operations. In contrast, OOP centers around objects—entities that encapsulate both state (data) and behavior (methods), like a Car class with attributes (speed) and actions (accelerate()).

C++ exemplifies OOP with features like encapsulation, modularity, and a rich library ecosystem, while maintaining backward compatibility with C. Its portability and cross-platform capabilities make it ideal for creating scalable and versatile software across various domains, from system programming to modern applications.

OOP-OBJECT ORIENETED  PROGRAMMING:               

Aspect

Function

Object

Purpose

To perform a specific operation or task

To represent an entity with state and behavior

State

Functions don’t maintain state (unless static)

Objects maintain their own internal state

Behavior

Functions encapsulate behavior (operations)

Objects have behavior through methods

Focus

Operations on data

Data and the behavior that acts on it

Programming Paradigm

Procedural Programming

Object-Oriented Programming (OOP)

Example

int add(int a, int b)

class Car { int speed; void accelerate(); }

While objects encapsulate both state and actions, typically in OOP-based design. Functions are more focused on behavior, while objects combine both data and the behavior that manipulates it.

Comparing Procedure oriented and object oriented programming:

Features of c++:

1. Object oriented programming concepts

2.  Encapsulation

Objects encapsulate data and methods.

3.  Modularity:

OOP encourages breaking code into objects that model real-world entities.

4.  Rich set of library:

  • Data structures:vector, list, map, etc.
  • Algorithms: Sorting, searching, and manipulation.
  • Iterators: For navigating through collections.

5. Backward Compatibility

 

C++ is derived from C and maintains backward compatibility, meaning it can directly use C libraries. This ensures that legacy systems written in C can be integrated with modern C++ code.

6. Cross-Platform Development

C++ is platform-independent and can be used to write programs that compile and run on multiple operating systems with minimal modification. This makes it suitable for software like browsers, database systems, and mobile applications.

7. Portability

C++ is platform-independent, meaning programs written in C++ can be compiled and run on various operating systems (Windows, Linux, macOS) with minimal changes.

8. Low-Level and High-Level Capabilities

Low-Level Programming: Provides fine control over hardware, memory management (e.g., pointers), and system resources.