Interface INotification:
namespace exercise90.Models;
internal interface INotification
{
public void SendMessage(string message);
}
Classe EmailNotification:
namespace exercise90.Models;
internal class EmailNotification : INotification
{
public void SendMessage(string message)
{
Console.WriteLine($"Sending EMAIL: {message}");
}
}
Classe PushNotification:
namespace exercise90.Models;
internal class PushNotification : INotification
{
public void SendMessage(string message)
{
Console.WriteLine($"Sending PUSH: {message}");
}
}
Classe SmsNotification:
namespace exercise90.Models;
internal class SmsNotification : INotification
{
public void SendMessage(string message)
{
Console.WriteLine($"Sending SMS: {message}");
}
}
Instâncias:
using exercise90.Models;
List<INotification> notifications = new List<INotification>
{
new EmailNotification(),
new SmsNotification(),
new PushNotification()
};
foreach (var notification in notifications)
{
notification.SendMessage("System is down!");
}