SOLID & Design Patterns Interview Question #145

How would you design notification delivery for Email, SMS, and Push?

Anti-Patterns, Refactoring, DI Lifetimes & Senior Design Scenarios Senior Advanced

Quick Interview Answer

Model notification channels behind a focused abstraction or Strategy implementations. Select one or several channels based on user preferences and business rules. Keep transport-specific concerns inside each implementation.

Detailed Explanation

Model notification channels behind a focused abstraction or Strategy implementations. Select one or several channels based on user preferences and business rules. Keep transport-specific concerns inside each implementation.

If all selected channels must receive the same notification, a composite can invoke multiple channel implementations. Retries and provider failures should be handled according to delivery requirements rather than hidden inside controllers.

Code Example

public interface INotificationChannel
{
    Task SendAsync(Notification message);
}

public class EmailChannel : INotificationChannel { }
public class SmsChannel : INotificationChannel { }
public class PushChannel : INotificationChannel { }