Thuta Learning
ရှာဖွေရန်
IntermediateProgrammingbeginner

OOP Introduction

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

Object-Oriented Programming (OOP) in JavaScript သည် objects များကို blueprint (classes) မှ တည်ဆောက်ခြင်းနှင့် code reusability တိုးမြှင့်ရန် နည်းလမ်းတစ်ခုဖြစ်သည်။

🎯 OOP Principles:

Encapsulation: Data နှင့် methods များကို object တစ်ခုတည်းတွင် စုစည်းခြင်း

Inheritance: Parent class မှ properties များကို child class က ရယူခြင်း

Polymorphism: Methods များကို different contexts များတွင် different ways ဖြင့် သုံးခြင်း

Abstraction: Complex details များကို ဖုံးကွယ်ခြင်း

javascript
// Constructor function (Old way)
function Person(name, age) {
    this.name = name;
    this.age = age;
    this.greet = function() {
        return `Hello, I'm ${this.name}`;
    };
}

const person1 = new Person("Aung Kyaw", 25);
console.log(person1.greet());
console.log(`Age: ${person1.age}`);

// ES6 Class (Modern way)
class Animal {
    constructor(name) {
        this.name = name;
    }
    speak() {
        return `${this.name} makes a sound`;
    }
}

const dog = new Animal("Buddy");
console.log(dog.speak());
You should see
Hello, I'm Aung Kyaw Age: 25 Buddy makes a sound
OOP Introduction | Thuta Learning