찐막.. 찐찐막
1. 오늘의 핵심 변화 요약
| 항목 | 변화 내용 |
|---|
| 메시지 책임 분리 | Message 생성 책임을 외부로 완전 위임 |
| Notification 도메인 정리 | 단순히 send(Message)를 수행하고 결과만 반환 |
| SendResult 구조 도입 | 전송 결과를 외부에서 판단 가능하게 분리 |
| NotificationSender 제네릭화 | 채널별 메시지에 따라 유연하게 구현체 연결 |
| SenderFactory 구조 정착 | NotificationType 기반 sender 인스턴스 반환 처리 |
| valueOf 안정화 | NotificationType.valueOf() → 예외 처리 추가 |
| 패키지 구조 정리 | 도메인, 메시지, 발송 구현, 구성 패키지 분리 완료 |
2. 최종 Notification 구조
public class Notification {
public SendResult sendExecute(String type, Message message) {
NotificationSender sender = SenderFactory.getSender(type);
return sender.send(message);
}
}
public enum NotificationType {
EMAIL(EmailNotificationSender.class),
SMS(SmsNotificationSender.class);
private final Class<? extends NotificationSender<?>> senderClass;
...
}
3. 추천 패키지 구조
com.study.notification
├── app
├── domain
│ ├── Notification.java
│ ├── NotificationSender.java
│ ├── SendResult.java
│ └── NotificationType.java
├── message
│ ├── Message.java
│ ├── EmailMessage.java
│ └── SmsMessage.java
├── sender
│ ├── EmailNotificationSender.java
│ ├── SmsNotificationSender.java
│ └── SenderFactory.java
└── config