[250416]Notification 모듈 리팩토링 리뷰

트라이캐치·2025년 4월 16일

출퇴근미니스터디

목록 보기
8/23
post-thumbnail

✅ 작업 범위

  • NotificationSender<T> 인터페이스 리팩토링
  • EmailNotificationSender 구현체 예외 처리 흐름 정비

🔹 NotificationSender 인터페이스

public interface NotificationSender<T extends Message> {
    /**
     * 메시지를 전송하고 결과를 반환합니다.
     * 전송 실패 시 예외가 발생할 수 있습니다.
     */
    SendResult send(T message) throws NotificationSendException;
}

✅ 리뷰 요약

  • T extends Message → 타입 안정성 확보
  • throws NotificationSendException → 예외 흐름 명시됨
  • JavaDoc 명세가 깔끔하게 작성됨 → 실무 수준 계약 명세

🔹 EmailNotificationSender 구현체

public SendResult send(EmailMessage message) throws NotificationSendException {
    try {
        Transport.send(null); // 실제 메시지 전송 생략
    } catch (MessagingException e) {
        Exception nextEx = e.getNextException();
        String errorCode = "SEND_ERROR";
        String errorMsg = nextEx.getMessage();
        throw new NotificationSendException("MAIL", errorCode, errorMsg);
    }
    return new SendResult(true, "success", null);
}

✅ 장점

  • 구체적인 예외 분기 및 메시지 해석 → 실무 예외 관리 흐름에 적합
  • 실패 시 예외 throw, 성공 시 SendResult 반환 → 명확한 분기

⚠ 개선 포인트

  • SendResult SendResult = ... → 변수명 camelCase로 수정 필요 (sendResult)
  • 성공 SendResult는 try 블록 성공 이후에 생성하는 편이 안전
  • Transport.send(null)은 명시적 TODO 코멘트 권장

🧠 티쳐 총평

  • 전반적으로 실무 수준의 예외 흐름과 구조를 갖춘 리팩토링
  • 세부 스타일과 흐름에서 한층 더 깔끔한 책임 분리를 정비할 수 있음
  • 다음 단계로 Notification 호출 구조 및 Factory 반환 안전성 연결 추천

0개의 댓글