Before Object-Oriented Programming (OOP) became the dominant paradigm, virtually all software was written in the Procedural style. Understanding why the industry abandoned procedural programming is essential to appreciating the design philosophy behind OOP.
In procedural programming, a program is structured as a sequence of instructions (procedures or functions) that operate on data. The data and the functions that manipulate that data are completely separate entities.
Languages like C, Pascal, and Fortran follow the procedural paradigm.
// Procedural approach in C
struct BankAccount {
int id;
double balance;
};
void deposit(struct BankAccount *acc, double amount) {
acc->balance += amount;
}
void withdraw(struct BankAccount *acc, double amount) {
acc->balance -= amount;
}
When projects grow from 1,000 lines to 1,000,000 lines, the procedural paradigm begins to collapse:
acc->balance. A single careless bug in a utility function can silently corrupt your bank balance. There are no access controls.balance to current_balance, you must find and update every single function in the entire codebase that touches it.PremiumBankAccount that works like a regular account but earns interest, you must copy-paste all the functions and modify them. There is no formal mechanism for extending existing code.OOP was designed from the ground up to solve these problems. Instead of separating data from functions, OOP bundles them together into a single, self-contained unit called an Object.
An object contains:
balance, accountHolder).deposit(), withdraw()).// Object-Oriented approach in Java
class BankAccount {
private double balance; // Data is HIDDEN
public void deposit(double amount) {
this.balance += amount;
}
public double getBalance() {
return this.balance;
}
}
The entire OOP paradigm rests on four fundamental principles:
Each of these pillars will be explored in dedicated chapters throughout this module.
Procedural programming is not dead. It remains excellent for:
OOP is preferred for: