<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.2.2" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Thoughts about Builder Pattern</title>
	<link>http://www.softonaut.com/2007/01/10/thoughts-about-builder-pattern/</link>
	<description>Exploring the space of software engineering</description>
	<pubDate>Tue, 06 Jan 2009 08:42:32 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.2</generator>

	<item>
		<title>By: rH</title>
		<link>http://www.softonaut.com/2007/01/10/thoughts-about-builder-pattern/#comment-3956</link>
		<author>rH</author>
		<pubDate>Thu, 01 Jan 2009 16:48:52 +0000</pubDate>
		<guid>http://www.softonaut.com/2007/01/10/thoughts-about-builder-pattern/#comment-3956</guid>
		<description>&#62;&#62;You are right this is not the “original” builder pattern from the GoF, but a new one presented from Josh Bloch’s at Java One.

A new one?!
"patterns allow developers to communicate using well-known, well understood names for software interactions"
Giving the same name to a different design is just plain Stupid....</description>
		<content:encoded><![CDATA[<p>&gt;&gt;You are right this is not the “original” builder pattern from the GoF, but a new one presented from Josh Bloch’s at Java One.</p>
<p>A new one?!<br />
&#8220;patterns allow developers to communicate using well-known, well understood names for software interactions&#8221;<br />
Giving the same name to a different design is just plain Stupid&#8230;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Xavi Miró</title>
		<link>http://www.softonaut.com/2007/01/10/thoughts-about-builder-pattern/#comment-3940</link>
		<author>Xavi Miró</author>
		<pubDate>Fri, 01 Aug 2008 18:19:23 +0000</pubDate>
		<guid>http://www.softonaut.com/2007/01/10/thoughts-about-builder-pattern/#comment-3940</guid>
		<description>@Mario,

   thank you! :-)

    I only had to complement your implementation. Although in general I prefer to avoid mutability in compile time, I haven't found a simple way to do it that didn't imply duplicating fields, so I chose this runtime check, which is a reasonable balance, in my opinion.

  Regards,

      Xavi</description>
		<content:encoded><![CDATA[<p>@Mario,</p>
<p>   thank you! <img src='http://www.softonaut.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>    I only had to complement your implementation. Although in general I prefer to avoid mutability in compile time, I haven&#8217;t found a simple way to do it that didn&#8217;t imply duplicating fields, so I chose this runtime check, which is a reasonable balance, in my opinion.</p>
<p>  Regards,</p>
<p>      Xavi</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Beautiful Java &#171; The science of lazy blogging</title>
		<link>http://www.softonaut.com/2007/01/10/thoughts-about-builder-pattern/#comment-3934</link>
		<author>Beautiful Java &#171; The science of lazy blogging</author>
		<pubDate>Sun, 06 Jul 2008 14:39:22 +0000</pubDate>
		<guid>http://www.softonaut.com/2007/01/10/thoughts-about-builder-pattern/#comment-3934</guid>
		<description>[...] [Builder pattern with named optional parameters: Effective Java (2nd Edition), Softonaut]     Posted by antonis Filed in English, Ελληνικά Tags: Java, [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] [Builder pattern with named optional parameters: Effective Java (2nd Edition), Softonaut]     Posted by antonis Filed in English, Ελληνικά Tags: Java, [&#8230;]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mario Hochreiter</title>
		<link>http://www.softonaut.com/2007/01/10/thoughts-about-builder-pattern/#comment-3933</link>
		<author>Mario Hochreiter</author>
		<pubDate>Tue, 01 Jul 2008 11:54:59 +0000</pubDate>
		<guid>http://www.softonaut.com/2007/01/10/thoughts-about-builder-pattern/#comment-3933</guid>
		<description>@Angelo Schneider
You are right this is not the "original" builder pattern from the GoF, but a new one presented from Josh Bloch's at Java One.

Please see also Xavi Miró's great Blog entry &lt;a href="http://xavimiro.blogspot.com/2008/04/new-builder-pattern.html" rel="nofollow"&gt;here&lt;/a&gt;.

@Xavi Miró
Great idea how to ensure immutability and i appreciate that you like my implementation ;-)</description>
		<content:encoded><![CDATA[<p>@Angelo Schneider<br />
You are right this is not the &#8220;original&#8221; builder pattern from the GoF, but a new one presented from Josh Bloch&#8217;s at Java One.</p>
<p>Please see also Xavi Miró&#8217;s great Blog entry <a href="http://xavimiro.blogspot.com/2008/04/new-builder-pattern.html" rel="nofollow">here</a>.</p>
<p>@Xavi Miró<br />
Great idea how to ensure immutability and i appreciate that you like my implementation <img src='http://www.softonaut.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Xavi Miró</title>
		<link>http://www.softonaut.com/2007/01/10/thoughts-about-builder-pattern/#comment-3932</link>
		<author>Xavi Miró</author>
		<pubDate>Tue, 01 Jul 2008 07:36:09 +0000</pubDate>
		<guid>http://www.softonaut.com/2007/01/10/thoughts-about-builder-pattern/#comment-3932</guid>
		<description>@Impatient,

    yes, you're right, this implementation can't ensure immutability. You can use duplication of fields as Josh does, or you can complement this implementation throwing exceptions when trying to build more than once the object and when trying to modifiy the object after it's been built. I prefer doing the latter, because I don't like duplicating fields. I have complemented this implementation in my blog, &lt;a href="http://xavimiro.blogspot.com/2008/04/new-builder-pattern.html" rel="nofollow"&gt;here&lt;/a&gt;.

  Regards,

     Xavi</description>
		<content:encoded><![CDATA[<p>@Impatient,</p>
<p>    yes, you&#8217;re right, this implementation can&#8217;t ensure immutability. You can use duplication of fields as Josh does, or you can complement this implementation throwing exceptions when trying to build more than once the object and when trying to modifiy the object after it&#8217;s been built. I prefer doing the latter, because I don&#8217;t like duplicating fields. I have complemented this implementation in my blog, <a href="http://xavimiro.blogspot.com/2008/04/new-builder-pattern.html" rel="nofollow">here</a>.</p>
<p>  Regards,</p>
<p>     Xavi</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Angelo Schneider</title>
		<link>http://www.softonaut.com/2007/01/10/thoughts-about-builder-pattern/#comment-3926</link>
		<author>Angelo Schneider</author>
		<pubDate>Sun, 29 Jun 2008 15:48:53 +0000</pubDate>
		<guid>http://www.softonaut.com/2007/01/10/thoughts-about-builder-pattern/#comment-3926</guid>
		<description>Hm,

this is not the builder pattern. The builder pattern is used to compose a set of objects in a certain way. E.g. create a "document", place a "title" and add a "paragraph".

In your example you only create one singel object (not a graph of objects) and you also use one concrete type for this object.

On the first glance your example indeed looks a bit like a builder but what you do there is writing a "fancy contructor".

A builder would work independent of the concrete object types and usually compose a graph, e.g. a document containing a title and a paragraph. The document and its nested objects then could be instances of HTMLDocumnet, HTMLTitle and  HTMLParagraph in one case or RTFDocument, RTFTitle and RTFParagraph in the other case.

Code using the builder would probably look like this: 
builder.start(); // get the builder ready to create a new document ... alternatively create a new builder
builder.setTitle("my title");
builder.addParagraph("my first paragraph");
builder.addParagraph("my second paragraph");
builder.getDocument(); // construct and _compose_ a document

Usually the point where the builder is used, has no knowledge wether an RTF or an HTML document is "builded".

Your example always knows and only can create ID3Tags ... therefor it is not the builder pattern.</description>
		<content:encoded><![CDATA[<p>Hm,</p>
<p>this is not the builder pattern. The builder pattern is used to compose a set of objects in a certain way. E.g. create a &#8220;document&#8221;, place a &#8220;title&#8221; and add a &#8220;paragraph&#8221;.</p>
<p>In your example you only create one singel object (not a graph of objects) and you also use one concrete type for this object.</p>
<p>On the first glance your example indeed looks a bit like a builder but what you do there is writing a &#8220;fancy contructor&#8221;.</p>
<p>A builder would work independent of the concrete object types and usually compose a graph, e.g. a document containing a title and a paragraph. The document and its nested objects then could be instances of HTMLDocumnet, HTMLTitle and  HTMLParagraph in one case or RTFDocument, RTFTitle and RTFParagraph in the other case.</p>
<p>Code using the builder would probably look like this:<br />
builder.start(); // get the builder ready to create a new document &#8230; alternatively create a new builder<br />
builder.setTitle(&#8221;my title&#8221;);<br />
builder.addParagraph(&#8221;my first paragraph&#8221;);<br />
builder.addParagraph(&#8221;my second paragraph&#8221;);<br />
builder.getDocument(); // construct and _compose_ a document</p>
<p>Usually the point where the builder is used, has no knowledge wether an RTF or an HTML document is &#8220;builded&#8221;.</p>
<p>Your example always knows and only can create ID3Tags &#8230; therefor it is not the builder pattern.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mohan</title>
		<link>http://www.softonaut.com/2007/01/10/thoughts-about-builder-pattern/#comment-3919</link>
		<author>Mohan</author>
		<pubDate>Thu, 08 May 2008 07:55:18 +0000</pubDate>
		<guid>http://www.softonaut.com/2007/01/10/thoughts-about-builder-pattern/#comment-3919</guid>
		<description>Really nice Example !! Thanks</description>
		<content:encoded><![CDATA[<p>Really nice Example !! Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Impatient</title>
		<link>http://www.softonaut.com/2007/01/10/thoughts-about-builder-pattern/#comment-3918</link>
		<author>Impatient</author>
		<pubDate>Mon, 21 Apr 2008 20:09:32 +0000</pubDate>
		<guid>http://www.softonaut.com/2007/01/10/thoughts-about-builder-pattern/#comment-3918</guid>
		<description>The question in my mind is whether your example preserves Bloch's priority of keeping the class immutable, and I believe the example is no. Using your code, you could have this situation:

ID3Tag.Builder builder = new ID3Tag.Builder("Bad", "U2").comment("not bad");
ID3Tag myTag = builder.build();
builder.comment("very bad!");

Here the myTag instance has been changed through builder, whereas in Bloch's example the builder has separate instance vars and the build() method creates a new instance each time it's called.</description>
		<content:encoded><![CDATA[<p>The question in my mind is whether your example preserves Bloch&#8217;s priority of keeping the class immutable, and I believe the example is no. Using your code, you could have this situation:</p>
<p>ID3Tag.Builder builder = new ID3Tag.Builder(&#8221;Bad&#8221;, &#8220;U2&#8243;).comment(&#8221;not bad&#8221;);<br />
ID3Tag myTag = builder.build();<br />
builder.comment(&#8221;very bad!&#8221;);</p>
<p>Here the myTag instance has been changed through builder, whereas in Bloch&#8217;s example the builder has separate instance vars and the build() method creates a new instance each time it&#8217;s called.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mario Hochreiter</title>
		<link>http://www.softonaut.com/2007/01/10/thoughts-about-builder-pattern/#comment-3915</link>
		<author>Mario Hochreiter</author>
		<pubDate>Thu, 13 Mar 2008 19:34:58 +0000</pubDate>
		<guid>http://www.softonaut.com/2007/01/10/thoughts-about-builder-pattern/#comment-3915</guid>
		<description>Hi michael.

You are right that i changed the original version a little bit. The reason is that i just did not want to repeat myself. Meaning that i did not want to have the same members in the outer and inner class as the original version does it.

The pro of this method is that if you add an additional member you do not need to type it twice. Furthermore, i think the members are logically correct belonging to the outer class but are not "correct" members for the builder itself.
The con of this variant is - as you already mentioned - that you cannot do some value consistency checks before constructing the outer object. But that may only be a valid con if the outer object is very expensive to create. In "normal" situations it´s totally o.k. to do the consistency checks in the build method and to throw an Exception for example IllegalArgumentException if some precondition is not met. 


Any other con`s you can think of?</description>
		<content:encoded><![CDATA[<p>Hi michael.</p>
<p>You are right that i changed the original version a little bit. The reason is that i just did not want to repeat myself. Meaning that i did not want to have the same members in the outer and inner class as the original version does it.</p>
<p>The pro of this method is that if you add an additional member you do not need to type it twice. Furthermore, i think the members are logically correct belonging to the outer class but are not &#8220;correct&#8221; members for the builder itself.<br />
The con of this variant is - as you already mentioned - that you cannot do some value consistency checks before constructing the outer object. But that may only be a valid con if the outer object is very expensive to create. In &#8220;normal&#8221; situations it´s totally o.k. to do the consistency checks in the build method and to throw an Exception for example IllegalArgumentException if some precondition is not met. </p>
<p>Any other con`s you can think of?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: michael</title>
		<link>http://www.softonaut.com/2007/01/10/thoughts-about-builder-pattern/#comment-3914</link>
		<author>michael</author>
		<pubDate>Wed, 12 Mar 2008 04:44:34 +0000</pubDate>
		<guid>http://www.softonaut.com/2007/01/10/thoughts-about-builder-pattern/#comment-3914</guid>
		<description>Neat example.  I saw the Bloch presentation too and his inner Builder class had member vars that mirrored the outer (product) class while in your example you do it a bit differently in calling the c'tor of the outer class from the Builder c'tor rather than its build() method.  Any thoughts on the pros and cons of each approach ?  My own idea is that value consistency checks, when required, would be best handled  in the build() method, followed by the the creation of the outer class instance in there too.</description>
		<content:encoded><![CDATA[<p>Neat example.  I saw the Bloch presentation too and his inner Builder class had member vars that mirrored the outer (product) class while in your example you do it a bit differently in calling the c&#8217;tor of the outer class from the Builder c&#8217;tor rather than its build() method.  Any thoughts on the pros and cons of each approach ?  My own idea is that value consistency checks, when required, would be best handled  in the build() method, followed by the the creation of the outer class instance in there too.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
