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 {
private INotifier GetNotifier(string notificationType) {
var preference = GetPreference(notificationType);
return preference == "text" ? textNotifier : emailNotifier;
public async Task SendReminder(string message, string recipient)
await GetNotifier("reminder").SendReminder(message, recipient);
public async Task SendExpirationWarning(DateTime expiration, string recipient)
await GetNotifier("warning").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");