
🎯 Lesson 1: Object-Oriented Programming (OOP) Introduction
1. OOP ဆိုတာဘာလဲ?
မြန်မာ → OOP (Object-Oriented Programming) ဆိုတာ programming paradigm တစ်ခုဖြစ်ပြီး, code ကို objects (data + behavior) အနေနဲ့ စီမံခန့်ခွဲတဲ့ နည်းလမ်း။
English → OOP is a programming paradigm where code is organized into objects that combine data (attributes) and behavior (methods).
2. Why OOP?
- Reusability → code ကို ပြန်သုံးနိုင်
- Modularity → အပိုင်းလိုက် ခွဲရေးနိုင်
- Maintainability → ပြန်ပြင်ရလွယ်
- Real-world modeling → objects = real-world entities
3. OOP vs Procedural Programming
| Feature | Procedural | OOP |
|---|---|---|
| Structure | Functions + data | Objects (data + methods) |
| Reuse | Harder | Easier (inheritance) |
| Example | add(x, y) | Calculator.add(x, y) |
4. OOP Core Concepts
- Class → Blueprint (design)
- Object → Instance of a class
- Encapsulation → Hide internal details
- Inheritance → Reuse parent class features
- Polymorphism → Same method, different behavior
- Abstraction → Hide complexity, show essentials
5. အကျဉ်းချုပ်
✅ OOP = organize code into objects
✅ Class = blueprint, Object = instance
✅ Core principles = Encapsulation, Inheritance, Polymorphism, Abstraction
✅ Makes code reusable, modular, and maintainable
python
# ===== 1. Define a Class =====
class Dog:
def __init__(self, name):
self.name = name
def bark(self):
return f"{self.name} says Woof!"
# ===== 2. Create Objects =====
dog1 = Dog("Bobby")
dog2 = Dog("Lucky")
print(dog1.bark()) # Bobby says Woof!
print(dog2.bark()) # Lucky says Woof!
# ===== 3. Real-World Analogy =====
print(f"\n===== Analogy =====")
print("Class = Blueprint of a house")
print("Object = Actual house built from blueprint")
print("Methods = Functions like open_door(), turn_on_light()")
print("Attributes = Properties like color, size")
# ===== 4. Advantages =====
print(f"\n===== Advantages =====")
print("✅ Organizes complex code")
print("✅ Easier debugging & testing")
print("✅ Encourages reuse (inheritance, polymorphism)")
print("✅ Closer to real-world thinking")You should see
Bobby says Woof! Lucky says Woof! ===== Analogy ===== Class = Blueprint of a house Object = Actual house built from blueprint Methods = Functions like open_door(), turn_on_light() Attributes = Properties like color, size ===== Advantages ===== ✅ Organizes complex code ✅ Easier debugging & testing ✅ Encourages reuse (inheritance, polymorphism) ✅ Closer to real-world thinking