What is Object-Oriented Programming?
Object-Oriented Programming (OOP) is a programming paradigm used in many languages. Learn the basic principles and concepts.
By Maksudul Haque (Moon)
•
Object-Oriented Programming (OOP) is a programming style that organizes code into objects.
An object contains both data (properties) and functions (methods).
Example in JavaScript:
class User {
constructor(name) {
this.name = name;
}
greet() {
console.log("Hello " + this.name);
}
}
const user1 = new User("John");
user1.greet();The four main principles of OOP are:
Encapsulation
Inheritance
Polymorphism
Abstraction
OOP helps developers write cleaner, more maintainable, and reusable code.