OOPs stands for Object Oriented Programming. OOP is a programming style with Classes, Objects, Inheritance, Polymorphism, Encapsulation, Abstraction. Before OOP, Procedural Programming like C was used, based on functions. C++ introduced OOP with Objects and Classes for data and functions. OOP provides a structured, reusable, and developer-friendly approach. It treats everything as objects, like Smalltalk, the first OOP language.
- Object:
Objects are runtime entities representing real-world and user-defined data. These are instances of classes and can be physical and logical entities. - Class:
Classes are blueprint for creating objects, a user-defined data type. These are collection of objects and a basic block for OOP implementation.
Four pillars of OOPs:
- Encapsulation: Wrapping data and functions in a class for restricted access.
- Abstraction: Representing essential features without background details.
- Inheritance: Objects acquire properties of other class objects, reducing redundancy.
- Polymorphism: Functions work in multiple forms based on input.
Features of OOPs:
- Message Passing: Objects communicate by sending and receiving information.
- Access Modifiers: Define how class members can be accessed.
- Abstract Class: Contains at least one pure virtual function without a definition.
- Exception Handling: Mechanism to handle program exceptions with try, throw, and catch.
Advantages of OOPs:
- Scalability
- Programmer-friendly, increased productivity
- Data security through data hiding, encapsulation, and abstraction
- Inheritance reduces redundant code, enhances readability, and reusability
- Polymorphism provides program flexibility
- Easy debugging
Disadvantages of OOPs:
- Not universally applicable
- Requires careful system structuring due to everything behaving like an object
- Tricky concept, needs thoughtful implementation
- May increase program length, leading to slower execution compared to others.
You can watch this good video about this topic –