A programming paradigm based on the concept of "objects," which contain data (attributes) & behavior (methods). OOP helps in designing software that is modular, reusable, scalable.
Encapsulation is the bundling of data (attributes) & methods that operate on that data within a single unit (object). It restricts direct access to some components, which helps in maintaining data integrity & security.
- Example: A class hides its internal state & only allows controlled access through public methods.
Abstraction is the process of hiding unnecessary details & exposing only the essential features of an object.
- Example: A car's driver interacts with the steering wheel & pedals without needing to understand the engine's internal mechanics.
Inheritance allows one class (child or subclass) to acquire the properties & behaviors of another class (parent or superclass). This promotes code reusability & hierarchical relationships.
- Example: A "Vehicle" class may have a subclass "Car" that inherits its properties like speed & fuel capacity but also has additional features like air conditioning.
Polymorphism allows the same operation to be performed in different ways based on the object that calls it. This makes code more flexible & scalable.
- Example: A function called "draw()" could be used for different shapes like circles, rectangles, triangles, each having its own implementation of "draw()".
- Modularity: Code is organized into objects & classes, making it easier to manage.
- Reusability: Classes and objects can be reused in different parts of the application or even in different projects.
- Scalability: OOP makes it easier to scale applications as they grow in complexity.
- Maintainability: Changes can be made to specific parts of the code without affecting the entire system.
- Security: Encapsulation helps protect data from unintended modifications.