Object-Oriented Programming (OOP): OOP is a programming paradigm that revolves around the concept of "objects." These objects are instances of classes, which act as blueprints for creating objects. Objects can encapsulate data (attributes or properties) and the methods (functions) that operate on that data. OOP aims to model real-world entities by representing them as objects with defined behaviors.
Key Concepts:
-
Class:
- A class is a blueprint or template that defines the structure and behavior of objects.
- It encapsulates data and methods that operate on the data.
- Objects are instances of a class.
-
Object:
- An object is an instance of a class, created based on the class's blueprint.
- Objects have attributes (data) and methods (functions) associated with them.
Advantages of OOP:
-
Modularity:
- OOP promotes modularity by breaking down a program into smaller, self-contained objects.
- Each object represents a specific part of the system, making it easier to understand and maintain.
-
Reusability:
- Objects and classes can be reused in different parts of a program or in different programs.
- This reduces redundancy and promotes code reuse.
-
Encapsulation:
- Encapsulation involves bundling data and methods that operate on the data within a single unit (an object).
- It hides the internal details of an object, providing a clean interface for interaction.
-
Abstraction:
- Abstraction allows developers to focus on essential features while hiding unnecessary details.
- Classes provide a level of abstraction, making it easier to work with complex systems.
-
Inheritance:
- Inheritance allows a new class (subclass/derived class) to inherit attributes and methods from an existing class (base class/parent class).
- It promotes code reuse and facilitates the creation of hierarchical class structures.
-
Polymorphism:
- Polymorphism allows objects to be treated as instances of their parent class, providing a unified interface.
- It enables flexibility in code, as objects can be used interchangeably.
- Combination of Noun, Adjective and Verb
- A Capsule that can Encapsule Data and
- Has some privet and Public Properties
- Has some function which is called Methods
- Is a custom data type
- A Isolated Environment for Properties and Methods