using System.Threading.Tasks;
public interface INotifier
Task SendReminder(string message, string recipient);
Task SendExpirationWarning(DateTime expiration, string recipient);
public class EmailNotifier : INotifier
public async Task SendReminder(string message, string recipient)
Console.WriteLine("Sending reminder email");
public async Task SendExpirationWarning(DateTime expiration, string recipient)
Console.WriteLine("Sending warning email");
public class TextNotifier : INotifier
public async Task SendReminder(string message, string recipient)
Console.WriteLine("Sending reminder text");
public async Task SendExpirationWarning(DateTime expiration, string recipient)
Console.WriteLine("Sending warning text");
public class NotificationService {
private readonly INotifier emailNotifier;
private readonly INotifier textNotifier;
public NotificationService()
emailNotifier = new EmailNotifier();
textNotifier = new TextNotifier();
private string GetPreference(string notificationType) {
return notificationType switch {
public async Task SendReminder(string message, string recipient)
var userPref = GetPreference("reminder");
textNotifier.SendReminder(message, recipient)
: emailNotifier.SendReminder(message, recipient)
public async Task SendExpirationWarning(DateTime expiration, string recipient)
var userPref = GetPreference("warning");
textNotifier.SendExpirationWarning(expiration, recipient)
: emailNotifier.SendExpirationWarning(expiration, recipient)
public static async Task Main()
var notifier = new NotificationService();
await notifier.SendReminder("foo", "bar");
await notifier.SendExpirationWarning(new DateTime(2025, 10, 20), "bar");