LLD Hub
Problems·Factory Pattern: Notification Creator
Design PatternsL3 · Medium

Factory Pattern: Notification Creator

Problem

A NotificationService creates different notification objects based on type: EMAIL, SMS, PUSH. Currently it has a giant switch-case inline. Extract a NotificationFactory that encapsulates object creation, so adding a new channel (e.g. SLACK) requires zero changes to NotificationService.

Requirements

  • Notification interface with: send(recipient, message), getChannel()
  • EmailNotification, SMSNotification, PushNotification each implement it
  • NotificationFactory.create(type: string): Notification
  • NotificationService uses factory — has no switch/if on type
  • Show adding SlackNotification: only add new class + register in factory

Constraints

  • NotificationService must not contain any type-switch logic
  • Factory should throw a clear error for unknown types
✓ Saved