이제 이 두 가지 방식이 추상화에서도 작동한다는 것을 증명해 보자. 다음 예제에서 볼 수 있듯이, 애플리케이션에 CommentNotificationProxy 인터페이스를 구현한 새로운 클래스인 CommentPushNotificationProxy를 추가하고 이 방식들을 하나씩 테스트해 보자. 예제를 구분하고자 sq-ch4-ex5라는 새 프로젝트를 만들었다. 이 예제는 sq-ch4-ex2 프로젝트의 코드를 기반으로 작성했다.
예제 4-13 CommentNotificationProxy 인터페이스에 대한 새로운 구현
@Component
public class CommentPushNotificationProxy
implements CommentNotificationProxy { ← 이 클래스는 CommentNotificationProxy 인터페이스를 구현한다.
@Override
public void sendComment(Comment comment) {
System.out.println(
"Sending push notification for comment: " + comment.getText());
}
}