OOP
1. **Definition**: Object-oriented programming is a programming paradigm based on the concept of
"objects," which can contain data in the form of fields (attributes) and code in the form of procedures
(methods).
2. **Four Pillars of OOP**:
- **Encapsulation**: Bundling data and methods that operate on the data into a single unit, called an
object, and restricting access to the internal state of the object.
- **Inheritance**: Allowing a class (subclass) to inherit properties and behaviors (methods) from
another class (superclass), promoting code reuse and facilitating the creation of hierarchical
relationships between classes.
- **Polymorphism**: Referring to the ability of objects of different classes to be treated as objects of a
common superclass, enabling dynamic method invocation and flexibility in code design.
- **Abstraction**: Simplifying complex systems by representing the relevant aspects without including
unnecessary details, allowing programmers to focus on essential features while hiding implementation
details.
3. **Classes and Objects**:
- **Class**: A blueprint for creating objects, defining attributes (fields) and behaviors (methods)
common to all objects of that type.
- **Object**: An instance of a class, representing a specific entity with its own set of attributes and
behaviors.
4. **Attributes and Methods**:
- **Attributes**: Variables that store data within objects, defining the state of an object.
- **Methods**: Functions or procedures that define the behavior of objects, performing operations on
object data.
5. **Encapsulation**:
- Encapsulation ensures that the internal state of an object is protected from unauthorized access and
modification by defining access modifiers (e.g., public, private, protected) for attributes and methods.
- Accessor methods (getters) and mutator methods (setters) provide controlled access to object
attributes.
6. **Inheritance**:
- Inheritance enables the creation of new classes (subclasses) based on existing classes (superclasses),
inheriting attributes and methods from the superclass.
- Subclasses can extend or override the behavior of superclass methods to tailor functionality to
specific requirements.
7. **Polymorphism**:
- Polymorphism allows objects of different classes to be treated as objects of a common superclass,
promoting code flexibility and reusability.
- Polymorphism is achieved through method overriding, where a subclass provides a specific
implementation of a method defined in its superclass.
8. **Abstraction**:
- Abstraction involves modeling real-world entities as simplified representations, focusing on essential
characteristics while hiding implementation details.
- Abstract classes and interfaces define common behaviors and methods without providing concrete
implementations, allowing subclasses to implement specific functionality.
9. **Examples of OOP Languages**:
- Common object-oriented programming languages include Java, C++, Python, C#, and Ruby, among
others.
These are fundamental concepts of object-oriented programming. Mastering these principles allows
developers to design modular, maintainable, and scalable software systems.