Object-Oriented Programming (OOP) is a programming paradigm that organizes code into objects, which are instances of classes. These objects represent real-world entities and can contain attributes (data) and methods (behavior). The main goal of OOP is to model complex systems by breaking them down into smaller, reusable, and self-contained objects that interact with each other.
🔗 Main Principles of OOP
- Encapsulation
Bundling data (fields) and behavior (methods) into a single unit (class) and restricting direct access to some of the object’s internal data. - Abstraction
Hiding complex implementation details and only exposing essential features to the outside world.
Example: ACar
class might expose astart()
method, but it hides the details of how the engine works internally.✅ Key idea: Show only what is necessary, hide everything else. - Inheritance
Allowing a class to inherit properties and methods from another class. This promotes code reuse. - Polymorphism
Objects can take many forms, meaning a single method can behave differently depending on the object that calls it.
Example: Adraw()
method behaves differently for aCircle
and aSquare
.