Introduction to OOP
Why OOP?
Problems with Functional/Procedural Programming:
- Does not model real-world problems well
- If new data is added, all functions need modification
- Global data is accessible to all functions
- No clear boundaries and well-defined code
- No Modularity: programs become monolithic and difficult to maintain
What is OOP?
- Programming style that divides a program into pieces of objects that can communicate with each other
- Objects-based coding style where each object (real-world entity) has its own attributes and behavior
- Fundamental idea: combine data and behavior into single unit → promotes Modularity
- OOP promotes modularity by encapsulating data and behavior within objects
Real-World Analogy
Student Rahul (Object)
├── Attributes: name, age, id, roll_no
└── Behaviors: study(), sleep(), bunk()
Classes and Objects
Basic Concepts
- Class: Blueprint that defines how an object looks
- Object: Instance of a class