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

Interfaces

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

Interface သည် class တစ်ခုက ဘာ methods/properties တွေရှိရမယ်ဆိုတာ သတ်မှတ်ပေးတဲ့ contract တစ်ခုပါ။ Interface ကို implement လုပ်တဲ့ class က interface ထဲက members တွေကို ရေးပေးရပါတယ်။

csharp
interface INotification
{
    void Send(string message);
}

class EmailNotification : INotification
{
    public void Send(string message)
    {
        Console.WriteLine($"Email sent: {message}");
    }
}

class SmsNotification : INotification
{
    public void Send(string message)
    {
        Console.WriteLine($"SMS sent: {message}");
    }
}

class Program
{
    static void Main(string[] args)
    {
        INotification notifier = new EmailNotification();
        notifier.Send("Welcome to ThutaTech");
    }
}

Interface အသုံးဝင်တဲ့နေရာ

Notification ကို email, SMS, push notification စတာတွေဖြင့်ပို့နိုင်ပေမယ့် app ရဲ့ main logic က Send() method တစ်ခုကိုပဲသိနေဖို့လိုပါတယ်။ Implementation ပြောင်းချင်ရင် class ပြောင်းလိုက်ရုံပါ။

You should see
Email sent: Welcome to ThutaTech
Interfaces | Thuta Learning