Refactoring to a fluent interface

Oren has a nice little gem where he introduces a nice refactoring for defining an email message. Fluent Interfaces introduce more a natural language flow to the code and walk you through the workflow of whatever task it is that you are performing. FluentInterfaces and DSLs (not the XML kind) go hand in hand in that a FluentInterface is often syntactic sugar for an Embedded or Internal DSL. In that case it's an abstraction from the code that allows you to focus on the problem rather than the nitty gritty details.

Personally I am big fan of Fluent interfaces and have thought more than a few times that we should be introducing usage of them within our guidance.

What are your thoughts?

Comments (2)

  1. I love the fluent interfaces developed my NMock, RhinoMock, NUnit 2.4 and the like.  I’ve had mixed success in building my own fluent interfaces.  I think the difficulty lies in the disconnect between what the method is designed to do, and having the method return an appropriate object to continue with a fluent phrase.

Skip to main content