<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Reinventing the wheel: the fluent interface design pattern</title>
	<atom:link href="http://lexandera.com/2009/04/reinventing-the-wheel-the-fluent-interface-design-pattern/feed/" rel="self" type="application/rss+xml" />
	<link>http://lexandera.com/2009/04/reinventing-the-wheel-the-fluent-interface-design-pattern/</link>
	<description>A blog about the web, mobile web, semantic web and mobile semantic web.</description>
	<lastBuildDate>Mon, 07 Jun 2010 20:16:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: alex</title>
		<link>http://lexandera.com/2009/04/reinventing-the-wheel-the-fluent-interface-design-pattern/comment-page-1/#comment-389</link>
		<dc:creator>alex</dc:creator>
		<pubDate>Fri, 17 Apr 2009 21:39:05 +0000</pubDate>
		<guid isPermaLink="false">http://lexandera.com/?p=316#comment-389</guid>
		<description>Yes, it is an awful idea; but that&#039;s the approach I&#039;ve seen used in fluent interfaces.
Let&#039;s take this command sequence from your example:
.i386()
.disk()
.size(150)
.disk()
.size(75)
.speed(7200)

You can see that disk() is called twice: after i386() and after size(). For this to be possible, both i386() and size() must either be returning the same object (which represents the whole computer) OR every class (processor, disk, ...) exposes methods for adding the next hardware component of any type, which would basically give you several almost identical classes. But if that&#039;s the case, you might just as well use a single class instead, because calling disk() on a processor object is just as awful as calling size() on a computer object.</description>
		<content:encoded><![CDATA[<p>Yes, it is an awful idea; but that&#8217;s the approach I&#8217;ve seen used in fluent interfaces.<br />
Let&#8217;s take this command sequence from your example:<br />
.i386()<br />
.disk()<br />
.size(150)<br />
.disk()<br />
.size(75)<br />
.speed(7200)</p>
<p>You can see that disk() is called twice: after i386() and after size(). For this to be possible, both i386() and size() must either be returning the same object (which represents the whole computer) OR every class (processor, disk, &#8230;) exposes methods for adding the next hardware component of any type, which would basically give you several almost identical classes. But if that&#8217;s the case, you might just as well use a single class instead, because calling disk() on a processor object is just as awful as calling size() on a computer object.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Batum</title>
		<link>http://lexandera.com/2009/04/reinventing-the-wheel-the-fluent-interface-design-pattern/comment-page-1/#comment-388</link>
		<dc:creator>Paul Batum</dc:creator>
		<pubDate>Fri, 17 Apr 2009 13:36:33 +0000</pubDate>
		<guid isPermaLink="false">http://lexandera.com/?p=316#comment-388</guid>
		<description>For each of those methods to be callable on the same object, the computer class would have to expose a size method for setting the size of a disk, and a speed method for setting the speed of the processor. For reasons that are self-evident, expecting your user to call these methods on the computer class rather than on the disk and processor class is an amazingly awful idea.</description>
		<content:encoded><![CDATA[<p>For each of those methods to be callable on the same object, the computer class would have to expose a size method for setting the size of a disk, and a speed method for setting the speed of the processor. For reasons that are self-evident, expecting your user to call these methods on the computer class rather than on the disk and processor class is an amazingly awful idea.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: alex</title>
		<link>http://lexandera.com/2009/04/reinventing-the-wheel-the-fluent-interface-design-pattern/comment-page-1/#comment-386</link>
		<dc:creator>alex</dc:creator>
		<pubDate>Sun, 12 Apr 2009 02:15:58 +0000</pubDate>
		<guid isPermaLink="false">http://lexandera.com/?p=316#comment-386</guid>
		<description>@superfav: Oops. Maybe I shouldn&#039;t have built my examples using the language I don&#039;t do much programming in. I actually had to pause and think for a couple of moments to figure out why it worked. :-) 
But I know from experience with other languages that many don’t support similar workarounds using anonymous classes and init blocks. Also, as you&#039;ve already mantioned it yourself, you can&#039;t do this if you get your object from a factory or try using an existing object...</description>
		<content:encoded><![CDATA[<p>@superfav: Oops. Maybe I shouldn&#8217;t have built my examples using the language I don&#8217;t do much programming in. I actually had to pause and think for a couple of moments to figure out why it worked. :-)<br />
But I know from experience with other languages that many don’t support similar workarounds using anonymous classes and init blocks. Also, as you&#8217;ve already mantioned it yourself, you can&#8217;t do this if you get your object from a factory or try using an existing object&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: alex</title>
		<link>http://lexandera.com/2009/04/reinventing-the-wheel-the-fluent-interface-design-pattern/comment-page-1/#comment-385</link>
		<dc:creator>alex</dc:creator>
		<pubDate>Sun, 12 Apr 2009 02:10:40 +0000</pubDate>
		<guid isPermaLink="false">http://lexandera.com/?p=316#comment-385</guid>
		<description>@Paul Batum: I believe that computer(), disk(), processor(), etc methods in your example could all still be returning the same object; calling them just changes its internal state. I encountered a similar example just yesterday, except that one was demonstrating how to build XML DOM trees.</description>
		<content:encoded><![CDATA[<p>@Paul Batum: I believe that computer(), disk(), processor(), etc methods in your example could all still be returning the same object; calling them just changes its internal state. I encountered a similar example just yesterday, except that one was demonstrating how to build XML DOM trees.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: superfav</title>
		<link>http://lexandera.com/2009/04/reinventing-the-wheel-the-fluent-interface-design-pattern/comment-page-1/#comment-384</link>
		<dc:creator>superfav</dc:creator>
		<pubDate>Sun, 12 Apr 2009 01:43:37 +0000</pubDate>
		<guid isPermaLink="false">http://lexandera.com/?p=316#comment-384</guid>
		<description>This is valid Java code:

# new JFrame(&quot;Hello World&quot;) {{
#     add(label, BorderLayout.CENTER);  
#     addWindowListener(new MainFrameListener());  
#     setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);  
#     pack();  
#     setLocationRelativeTo(null);  
#     setVisible(true);  
# }};

But it&#039;s not fluent, like StringBuffer&#039;s append, just syntactic sugar that works for this particular case.</description>
		<content:encoded><![CDATA[<p>This is valid Java code:</p>
<p># new JFrame(&#8220;Hello World&#8221;) {{<br />
#     add(label, BorderLayout.CENTER);<br />
#     addWindowListener(new MainFrameListener());<br />
#     setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);<br />
#     pack();<br />
#     setLocationRelativeTo(null);<br />
#     setVisible(true);<br />
# }};</p>
<p>But it&#8217;s not fluent, like StringBuffer&#8217;s append, just syntactic sugar that works for this particular case.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Batum</title>
		<link>http://lexandera.com/2009/04/reinventing-the-wheel-the-fluent-interface-design-pattern/comment-page-1/#comment-383</link>
		<dc:creator>Paul Batum</dc:creator>
		<pubDate>Sun, 12 Apr 2009 01:04:32 +0000</pubDate>
		<guid isPermaLink="false">http://lexandera.com/?p=316#comment-383</guid>
		<description>Sigh. Follow the link for a version with whitespace...</description>
		<content:encoded><![CDATA[<p>Sigh. Follow the link for a version with whitespace&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Batum</title>
		<link>http://lexandera.com/2009/04/reinventing-the-wheel-the-fluent-interface-design-pattern/comment-page-1/#comment-382</link>
		<dc:creator>Paul Batum</dc:creator>
		<pubDate>Sun, 12 Apr 2009 01:02:48 +0000</pubDate>
		<guid isPermaLink="false">http://lexandera.com/?p=316#comment-382</guid>
		<description>Your statement may be true for some small number of fluent interface implementations, such as jQuery&#039;s where the &#039;query object&#039; is always the active object. However many fluent interface implementations will return a different object at times and then the next method call applies to that different object. The with keyword does not achieve this - it guarantees that each method executes on the object you defined in the with.

Here is a really simple example from &lt;a href=&quot;http://martinfowler.com/dslwip/InternalOverview.html&quot; rel=&quot;nofollow&quot;&gt;Fowler&#039;s work in progress book on DSL&#039;s&lt;/a&gt;:

  computer()
    .processor()
      .cores(2)
      .i386()
    .disk()
      .size(150)
    .disk()
      .size(75)
      .speed(7200)
      .sata()
    .end();

Do you see how noisy that would be if you were trying to achieve the same thing using the with keyword?</description>
		<content:encoded><![CDATA[<p>Your statement may be true for some small number of fluent interface implementations, such as jQuery&#8217;s where the &#8216;query object&#8217; is always the active object. However many fluent interface implementations will return a different object at times and then the next method call applies to that different object. The with keyword does not achieve this &#8211; it guarantees that each method executes on the object you defined in the with.</p>
<p>Here is a really simple example from <a href="http://martinfowler.com/dslwip/InternalOverview.html" rel="nofollow">Fowler&#8217;s work in progress book on DSL&#8217;s</a>:</p>
<p>  computer()<br />
    .processor()<br />
      .cores(2)<br />
      .i386()<br />
    .disk()<br />
      .size(150)<br />
    .disk()<br />
      .size(75)<br />
      .speed(7200)<br />
      .sata()<br />
    .end();</p>
<p>Do you see how noisy that would be if you were trying to achieve the same thing using the with keyword?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: atleta</title>
		<link>http://lexandera.com/2009/04/reinventing-the-wheel-the-fluent-interface-design-pattern/comment-page-1/#comment-381</link>
		<dc:creator>atleta</dc:creator>
		<pubDate>Sun, 12 Apr 2009 00:32:28 +0000</pubDate>
		<guid isPermaLink="false">http://lexandera.com/?p=316#comment-381</guid>
		<description>This whole fluent thingy is not about sparing a few characters and making up for the lack of the with statement. It&#039;s about creating API that really allows expressing what you want in an (almost) fluent English style, orin other words creating a DSL. Have a look the jmock/hamcrest examples. E.g. this one is a JUnit+hamcrest one: assertThat(responseString, either(containsString(&quot;color&quot;)).or(containsString(&quot;colour&quot;)));

Though it really makes look java like LISPified English :)</description>
		<content:encoded><![CDATA[<p>This whole fluent thingy is not about sparing a few characters and making up for the lack of the with statement. It&#8217;s about creating API that really allows expressing what you want in an (almost) fluent English style, orin other words creating a DSL. Have a look the jmock/hamcrest examples. E.g. this one is a JUnit+hamcrest one: assertThat(responseString, either(containsString(&#8220;color&#8221;)).or(containsString(&#8220;colour&#8221;)));</p>
<p>Though it really makes look java like LISPified English :)</p>
]]></content:encoded>
	</item>
</channel>
</rss>
