Timothy Khouri - SingingEels.com

I subscribe to the "take it apart and rebuild it" approach to learning.

A "Fluent Interface" to XML!

I've been getting into this kick on fluent interfaces, and recently posted a blog post about fluent interfaces using XML as an example. Here's a snippet from my post:

string result = FluentInterfaceForXml
       .Element("root")
           .WithNode("person")
               .WithAttribute("firstName", "Timothy")
               .WithAttribute("lastName", "Khouri")

It makes me wonder if Microsoft will start developing fluent interfaces for some of their existing technologies? (possibly in a seperate DLL like Enterprise Library). Do any of you developers out there see yourslef writing your own alternate API's in this sort of "human language-esq", method-chaining style?

Check out the blog post - I've included a screen shot of the results and the full source code for the project to show how I did it: http://www.singingeels.com/Blogs/Nullable/2008/07/18/Fluent_Interfaces_to_XML_My_Example_of_Fluent_Interfaces.aspx

Comments

haidar_bilal said:

Hi Timothy,

I once had a post about this topic and using Fluent Interfaces I was able to build a very nice way to deal with an inhouse-developed Search Engine at work.

I was able to cut down code-statements to 1/4.

Check it out:

bhaidar.net/.../fluent-interface-in-c.aspx

Regards

# July 19, 2008 5:25 AM

Don Demsak said:

You can't get any more of a fluent interface than VB's XML Literals, which uses LINQ to XML under the hood.  I know you mentioned that L2X is cleaner, but you still don't like it.  I know it is VB, but just try XML Literals, it is the most fluent XML interface you can create (because it IS XML).

# July 19, 2008 2:51 PM

Jesse Ezell said:

Looks pretty much like XDocument/XElement, etc. to me.

# July 20, 2008 12:32 PM

Nullable said:

Good comments, but I think the point was missed. This post wasn't about XML... it's about Fluent Interfaces.

The XML part was just an *example* of what a fluent interface is :)

Thanks,

-Timothy

# July 22, 2008 11:14 AM