http://martinfowler.com/bliki/FluentInterface.html

이름은 좀 멋지지만 별거 아니라는...

        Statistics statistics = new Statistics(StatisticsChartType.MOTION, "스터디 참석자 통계 그래프");
        statistics.addColumn(StatisticsColumnType.STRING, "스터디 이름");
        statistics.addColumn(StatisticsColumnType.DATE, "모임 날짜");
        statistics.addColumn(StatisticsColumnType.NUMBER, "참석자 수");
        statistics.addColumn(StatisticsColumnType.NUMBER, "모임 횟수");
        statistics.addColumn(StatisticsColumnType.NUMBER, "참석율");
        statistics.addColumn(StatisticsColumnType.STRING, "스터디 상태");
        statistics.addColumn(StatisticsColumnType.STRING, "모임명 이름");

이 코드는 얼마전에 봄싹 사이트에 Statistics 메뉴를 추가하면서 코딩한 것인데 오늘 보다가 갑자기 Fluent Interface가 떠올랐습니다. 그래서 적용해봤지요.

        Statistics statistics = new Statistics(StatisticsChartType.MOTION, "스터디 참석자 통계 그래프")
            .withColumn(StatisticsColumnType.STRING, "스터디 이름")
            .withColumn(StatisticsColumnType.DATE, "모임 날짜")
            .withColumn(StatisticsColumnType.NUMBER, "참석자 수")
            .withColumn(StatisticsColumnType.NUMBER, "모임 횟수")
            .withColumn(StatisticsColumnType.NUMBER, "참석율")
            .withColumn(StatisticsColumnType.STRING, "스터디 상태")
            .withColumn(StatisticsColumnType.STRING, "모임명 이름");

조금 fluent 하게 보이나요??ㅋ 객체를 다 만든 다음에 추가하는게 아니라 객체 만들 때 메서드를 연달아 호출하는 모양이여서 메서드 이름을 add -> with로 변경했습니다. 메서드 리턴 타입도 당연히 바꿨지요.

장점은 저렇게 조금 API가 이쁘고 사용하기 편해진다는 것이고 단점은 디버깅할 때 조금 불편할 수 있다는데.. 머.. 글쎄요. 그다지...