2007/01/08 00:15 Developer
ExpressionBuilder
http://martinfowler.com/bliki/DomainSpecificLanguage.html
http://www.mockobjects.com/files/evolving_an_edsl.ooplsa2006.pdf
.with(6, "TAL")
.with(5, "HPK").skippable()
.with(3, "LGV")
.priorityRush();
하지만, MF의 글중에서 다음과 같은 글도 읽었을 것입니다.
1. 명령과 질의를 분리해라
2. 인터페이스는 간결화하고, 최소화해라.
http://martinfowler.com/bliki/CommandQuerySeparation.html
http://martinfowler.com/bliki/MinimalInterface.html
그러면, API를 디자인을 할때 헷갈리기 시작합니다. 도데체 나보고 어쩌란 얘기냐?
Fluent Interface를 구현하려면, 당연히 Human Interface화 되어야 하는거 아닌가?
물론, evolving_an_edsl.ooplsa2006에서도 관련 내용이 나와있지만, 이런 상황에서 MF아저씨는 다음과 같은 코드로 해결 방법을 가르켜줍니다.
facade or builder틱한 builder layer가 생기겠지만, 위의 원칙들은 지켜줄수 있습니다.
가만히 생각해보면, 알게 모르게 OOP에 있어서 구현과 인터페이스를 분리시켜주는 역할에 builder pattern이 자주 사용되고 있습니다. API를 만들어서 공개를 할때 신경써야 할게 너무 많네요..^^
public class OrderBuilder {
private Order subject = new Order();
private OrderLine currentLine;
public OrderBuilder with(int quantity, String productCode) {
currentLine = new OrderLine(quantity, Product.find(productCode));
subject.addLine(currentLine);
return this;
}
public OrderBuilder skippable() {
currentLine.setSkippable(true);
return this;
}
public OrderBuilder priorityRush() {
subject.setRush(true);
return this;
}
public Order getSubject() {
return subject;
}
}
북치고 장구치고 다하는 MF의 bliki의 글들이었습니다.
ExpressionBuilder
http://martinfowler.com/bliki/ExpressionBuilder.html
