vendredi 22 juillet 2022

Multiple channel Notification system - LLD -

You have to design the classes for building a notification system that supports multiple channels such as email, SMS, Whatsapp. It should be easily extensible.

My design :

class Message {
NotificationType type ; //email, sms
msgId;
String content ;
}
MessagingServiceImpl {
static {
//map from notification type to the respective handler
map.put("SMS",new SMSHandler());
map.put("Email",new EmailHandler();
}
void processMessage(Message message) {
Handler handler = map.get(message.getNotificationType();
handler.handleMessage();
}
}
public abstract class Handler {
public abstract void handle(Mesage message) ;
}
public EmailHandler extends Handler {
public void handle(Message message) {
System.out.println("Sending email"): // similar class for phone.
}

Note: This design was rejected in the interview. Questions:

  1. Should we make Message abstract - EmailMessage,SMSMessage etc ?
  2. Note that the content of the message varies depending on the channel. For eg. In email,the content will be large. For SMS,it is much smaller. So,should Message be astract?
  3. How can you support a new channel eg..telegram messages with minimal changes?

Aucun commentaire:

Enregistrer un commentaire