ch 1 oops
1️⃣ Introduction to Object Oriented Thinking (OOT)
Object Oriented Thinking is a way of solving problems by modeling real-world entities as objects.
Instead of thinking in terms of functions (like procedural programming), we think in terms of:
-
Objects
-
Classes
-
Data
-
Behavior
👉 Real world example:
A Car has:
-
Data → color, speed, model
-
Behavior → start(), stop(), accelerate()
We combine both in one unit → Object
2️⃣ Introduction to Object Oriented Programming (OOP)
Object Oriented Programming (OOP) is a programming paradigm that organizes software design around objects rather than functions.
In C++, OOP is implemented using:
-
Classes
-
Objects
-
Inheritance
-
Polymorphism
-
Encapsulation
-
Abstraction
3️⃣ Comparison: Procedural Programming vs Object Oriented Programming
| Basis | Procedural Programming | Object Oriented Programming |
|---|---|---|
| Focus | Functions | Objects |
| Approach | Top-down | Bottom-up |
| Data Security | Less secure | More secure |
| Code Reusability | Limited | High (Inheritance) |
| Example Language | C | C++ |
🔹 Example (Procedural – C Style)
#include <iostream>
using namespace std;
int add(int a, int b) {
return a + b;
}
int main() {
cout << add(5, 3);
}
🔹 Example (OOP – C++)
#include <iostream>
using namespace std;
class Calculator {
public:
int add(int a, int b) {
return a + b;
}
};
int main() {
Calculator obj;
cout << obj.add(5, 3);
}
4️⃣ Features of Object Oriented Paradigm
1. Encapsulation
Wrapping data and functions into a single unit (class).
2. Abstraction
Hiding internal details and showing only necessary features.
3. Inheritance
One class acquires properties of another class.
4. Polymorphism
One function behaves differently in different situations.
5. Message Passing
Objects communicate through function calls.
5️⃣ Merits of OOP
✅ Code Reusability
✅ Data Security
✅ Easy Maintenance
✅ Real-world Modeling
✅ Scalability
✅ Reduced Complexity
6️⃣ Demerits of OOP
❌ Larger Program Size
❌ Slower Execution (sometimes)
❌ Complex Design
❌ Not suitable for small programs
7️⃣ Object Model
The Object Model describes how objects interact and are structured.
It consists of:
-
Abstraction
-
Encapsulation
-
Modularity
-
Hierarchy
-
Typing
-
Concurrency
-
Persistence
👉 In simple words:
Object model defines how real-world entities are converted into software objects.
8️⃣ Elements of OOPS (Important for Exam)
🔹 Class
Blueprint of object.
class Student {
int roll;
};
🔹 Object
Instance of class.
Student s1;
🔹 Data Members
Variables inside class.
🔹 Member Functions
Functions inside class.
🔹 Constructor
Special function to initialize object.
🔹 Destructor
Special function to destroy object.
🔹 Inheritance
class A {};
class B : public A {};
🔹 Polymorphism
Function Overloading / Function Overriding
9️⃣ Input/Output Processing in C++
C++ uses iostream library.
Header File:
#include <iostream>
using namespace std;
Input:
int a;
cin >> a;
Output:
cout << a;
Example:
#include <iostream>
using namespace std;
class Student {
public:
string name;
int roll;
void input() {
cout << "Enter Name: ";
cin >> name;
cout << "Enter Roll: ";
cin >> roll;
}
void display() {
cout << "Name: " << name << endl;
cout << "Roll: " << roll << endl;
}
};
int main() {
Student s1;
s1.input();
s1.display();
}
Comments
Post a Comment