Giao diện
Part 3: Object-Oriented Programming Intermediate
Từ tư duy thủ tục sang tư duy đối tượng — Mô hình hóa thế giới thực bằng C++ Classes
Tại sao OOP?
OOP không chỉ là "cách viết code khác" — nó là cách tư duy về phần mềm. Thay vì nghĩ "làm gì" (functions), ta nghĩ "ai làm gì" (objects).
┌─────────────────────────────────────────────────────────────────┐
│ PROCEDURAL vs OOP THINKING │
├─────────────────────────────────────────────────────────────────┤
│ │
│ PROCEDURAL (C-style) OOP (C++ Classes) │
│ ───────────────────── ───────────────── │
│ │
│ struct Player { class Player { │
│ int health; private: │
│ int mana; int health_; │
│ }; int mana_; │
│ public: │
│ void attack(Player* p, void attack(Enemy& target); │
│ Enemy* e); void heal(int amount); │
│ void heal(Player* p, }; │
│ int amount); │
│ │
│ // Data và functions tách rời // Data + behavior = Object │
│ │
└─────────────────────────────────────────────────────────────────┘Module Structure
📘 Part 1: Encapsulation & Abstraction
| Topic | Description |
|---|---|
| Tại sao OOP? | Philosophy, mapping real world to code |
| Class Anatomy | Members, Methods, Constructor/Destructor |
| Access Modifiers | public, private, protected, Data Hiding |
| The this Pointer | What it is and when to use |
| Member Initialization | Modern initialization list |
| 🎮 RPG Character Project | Practical example |
📙 Part 2: Inheritance & Polymorphism
| Topic | Description |
|---|---|
| Inheritance Basics | Base/Derived classes, access specifiers |
| Virtual Functions | virtual, override, final, vtable |
| Polymorphism | Runtime dispatch, OCP principle |
| Abstract Classes | Pure virtual, interfaces |
| 🎮 RPG Class System | Warrior/Mage/Rogue implementation |
Prerequisites
Trước khi bắt đầu Part 3, bạn cần nắm vững:
📋 YÊU CẦU
- ✅ Pointers & References
- ✅ Functions (pass-by-reference)
- ✅ Scope & Lifetime
- ✅ const Best Practices
Learning Path
"Object-oriented programming lets you think in terms of problems rather than the machine." — Alan Kay