데코레이터 패턴이란?

IMG_383E16D158EF-1.jpeg

구현하기

Component Interface

public interface CommentService {
    void addComment(String comment);
}

Concrete Component

public class DefaultCommentService implements CommentService {

    @Override
    public void addComment(String comment) {
        System.out.println(comment);
    }

}

Decorator

Component 하나를 래핑

public class CommentDecorator implements CommentService {
    private CommentService commentService;

    public CommentDecorator(CommentService commentService) {
        this.commentService = commentService;
    }

    @Override
    public void addComment(String comment) {
        commentService.addComment(comment);
    }
}