To design a notification system, we must first understand how it will be used. The system should:
User
UserPreference
Notification
NotificationStrategy
EmailNotification
SMSNotification
PushNotification
NotificationService
Scheduler
RetryMechanism
Channel class with common attributes and methods. Derive EmailChannel, SMSChannel, and PushChannel for channel-specific logic.Notification class and extend it for different types like TransactionalNotification and PromotionalNotification.Channel class with specific implementations for EmailChannel, SMSChannel, PushChannel, etc.Notification class for different notification types.p
public enum NotificationType{
Sms,
Push,
Email
}
public enum NotificationFrequency{
Daily,
Weekly,
Immediately
}
public enum Status{
Pending,
Sent,
Failed
}
public class User{
private String userId;
private String userName;
private UserPreference preferences;
public User(String userId,String userName){
this.userId=userId;
this.userName=userName;
}
public UserPreference getUserPreference(){
return preferences;
}
public void setUserPreference(UserPreference pref){
this.preferences=pref;
}
}
public class UserPreference{
private List<NotificationType> types;
private String frequency;
private int quietHours;
//setters for types,frequency,quietHours
}
public class Notification{
private String id;
private String content;
private NotificationType type;
private Status status;
//setters and constructors
}
public interface NotificationStrategy{
public void send(User user,Notification notification);
}
public class SmsNotification implements NotificationStrategy{
@Override
public void send(User user,Notification notification){
// logic to send sms
}
}
public class PushNotification implements NotificationStrategy{
@Override
public void send(User user,Notification notification){
// logic to send sms
}
}
public class EmailNotification implements NotificationStrategy{
@Override
public void send(User user,Notification notification){
// logic to send sms
}
}
public class NotificationService{
NotificationStrategy strategy;
public NotificationService(NotificationStrategy strategy){
this.strategy=strategy;
}
public void setStrategy(NotificationStrategy strategy){
this.strategy=strategy;
}
public void sendNotification(User user,Notification notification){
strategy.send(user,notification);
}
}
Check and explain whether your design adheres to solid principles (Ask interviewer what SOLID principle is if you can not recall it.)...
Explain how your design can handle changes in scale and whether it would be easily to extend with new functionalities...
Try creating a class, flow, state and/or sequence diagram using the diagramming tool. Mermaid flow diagrams can be used to represent system use cases. You can ask the interviewer bot to create a starter diagram if unfamiliar with the tool. Briefly explain your diagrams if necessary...
Critically examine your design for any flaws or areas for future improvement...