2006/12/10 01:03 Developer
Normal vs Fluent interface
Normal vs Fluent interface
* Normal Style
private void makeNormal(Customer customer) {
Order o1 = new Order();
customer.addOrder(o1);
OrderLine line1 = new OrderLine(6, Product.find("TAL"));
o1.addLine(line1);
OrderLine line2 = new OrderLine(5, Product.find("HPK"));
o1.addLine(line2);
OrderLine line3 = new OrderLine(3, Product.find("LGV"));
o1.addLine(line3);
line2.setSkippable(true);
o1.setRush(true);
}
Order o1 = new Order();
customer.addOrder(o1);
OrderLine line1 = new OrderLine(6, Product.find("TAL"));
o1.addLine(line1);
OrderLine line2 = new OrderLine(5, Product.find("HPK"));
o1.addLine(line2);
OrderLine line3 = new OrderLine(3, Product.find("LGV"));
o1.addLine(line3);
line2.setSkippable(true);
o1.setRush(true);
}
* Fluent Style
private void makeFluent(Customer customer) {
customer.newOrder()
.with(6, "TAL")
.with(5, "HPK").skippable()
.with(3, "LGV")
.priorityRush();
}
customer.newOrder()
.with(6, "TAL")
.with(5, "HPK").skippable()
.with(3, "LGV")
.priorityRush();
}
오늘은 DDD에 대한 소식을 듣고, 예전에 봤던 글들을 다시 한번 봤다. 또, 느낌이 틀리다.
전에 봤던 그 느낌하고, 지금 느낌은 또 틀리다. 이 글을 또 나중에 한번 더 봐야겠다.
JMock's contains a very nice fluent API
mock.expects(once()).method("m").with( or(stringContains("hello"),
stringContains("howdy")) );
stringContains("howdy")) );
JMock은 martin fowler가 생각하는 매우 나이스한 fluent API의 모습이다.
Joda Time에서 얘기하는 장점중의 일부를 간추렸다. 3가지를 추렸는데, fluent API의 장점하고 같다.
- Easy To use
- Easy To Extend
- Good Test Coverage
주로, 사용자 관점에서의 API는 좀더 편하게 사용할수 있는 인터페이스가 더 좋은 API라는 생각을 한다. 그런 관점에서는 fluent API들은 너무도 직관적이고, 이해하기가 쉽다.
DomainSpecificLanguage
http://www.martinfowler.com/bliki/DomainSpecificLanguage.html
DslBoundary
http://www.martinfowler.com/bliki/DslBoundary.html
Generating Code for DSLs
http://www.martinfowler.com/articles/codeGenDsl.html
EvansClassification
http://www.martinfowler.com/bliki/EvansClassification.html
FluentInterface
http://www.martinfowler.com/bliki/FluentInterface.html
TimeAndMoney Java Code Library
http://timeandmoney.domainlanguage.com/
Joda Time - Java date and time API
http://joda-time.sourceforge.net/
March is Not a Number
http://www.eaipatterns.com/ramblings/40_marchnan.html
EDSL
http://altlang.org/fest/%EC%96%B8%EC%96%B4%EC%86%8D%EC%96%B8%EC%96%B4
오늘은 김창준님이 대안언어축제했던 발표문서를 보다가 정말 여러가지 건졌다.
아주 재미있는 글들이 많았다.
요즘 한창 잘나가는 eric evans와 우리의 영원한 영웅 martin fowler의 사진을 올려본다.
두 분땜시 참 여러가지로 도움이 많이 된다.