<?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: A Better Builder</title>
	<atom:link href="http://www.jakubkorab.net/2009/10/a-better-builder.html/feed" rel="self" type="application/rss+xml" />
	<link>http://www.jakubkorab.net/2009/10/a-better-builder.html</link>
	<description>Tech, Opinion, and Doing Stuff</description>
	<lastBuildDate>Wed, 03 Mar 2010 16:42:55 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Jake</title>
		<link>http://www.jakubkorab.net/2009/10/a-better-builder.html/comment-page-1#comment-701</link>
		<dc:creator>Jake</dc:creator>
		<pubDate>Thu, 15 Oct 2009 10:52:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.jakubkorab.net/?p=226#comment-701</guid>
		<description>If by extending with a mock, you mean extend the class under test and stub out methods, then yeah you could certainly do that, but it&#039;s not nice. The advantage that dynamic mock frameworks like easymock give you in this instance is brevity of code and flexibility.

expect(mockBuilder.buildDoor(otherDoorData)).andReturn(new Door());
expect(mockBuilder.buildWindow(otherWindowData)).andThrow(new NumberFormatException());

is much easier to deal with than the following repeated a dozen times in your unit tests:

builder = new HouseBuilder() {
    @Override
    Window buildDoor(OtherDoorType otherDoorData) {
        return new Door();
    }

    @Override
    Window buildWindow(OtherWindowType otherWindowData) {
        throw new NumberFormatException();
    }
}

In fact the latter approach may not be possible if your builder class is final. You may also need to call a method more than once and have it return different values:

expect(mockBuilder.buildDoor(otherDoorData)).andReturn(new Door());
expect(mockBuilder.buildDoor(moreDoorData)).andThrow(new IllegalStateException(&quot;You already have a door&quot;));</description>
		<content:encoded><![CDATA[<p>If by extending with a mock, you mean extend the class under test and stub out methods, then yeah you could certainly do that, but it&#8217;s not nice. The advantage that dynamic mock frameworks like easymock give you in this instance is brevity of code and flexibility.</p>
<p>expect(mockBuilder.buildDoor(otherDoorData)).andReturn(new Door());<br />
expect(mockBuilder.buildWindow(otherWindowData)).andThrow(new NumberFormatException());</p>
<p>is much easier to deal with than the following repeated a dozen times in your unit tests:</p>
<p>builder = new HouseBuilder() {<br />
    @Override<br />
    Window buildDoor(OtherDoorType otherDoorData) {<br />
        return new Door();<br />
    }</p>
<p>    @Override<br />
    Window buildWindow(OtherWindowType otherWindowData) {<br />
        throw new NumberFormatException();<br />
    }<br />
}</p>
<p>In fact the latter approach may not be possible if your builder class is final. You may also need to call a method more than once and have it return different values:</p>
<p>expect(mockBuilder.buildDoor(otherDoorData)).andReturn(new Door());<br />
expect(mockBuilder.buildDoor(moreDoorData)).andThrow(new IllegalStateException(&#8220;You already have a door&#8221;));</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Graham Williamson</title>
		<link>http://www.jakubkorab.net/2009/10/a-better-builder.html/comment-page-1#comment-700</link>
		<dc:creator>Graham Williamson</dc:creator>
		<pubDate>Wed, 14 Oct 2009 18:10:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.jakubkorab.net/?p=226#comment-700</guid>
		<description>Hi Jakub

I had another thought...

Couldn&#039;t the same swappable behaviour be achieved by simply extending the builder with a mock builder and overriding the methods you don&#039;t want to test? I.e. use the flexibility that say the template method pattern affords?</description>
		<content:encoded><![CDATA[<p>Hi Jakub</p>
<p>I had another thought&#8230;</p>
<p>Couldn&#8217;t the same swappable behaviour be achieved by simply extending the builder with a mock builder and overriding the methods you don&#8217;t want to test? I.e. use the flexibility that say the template method pattern affords?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Interesting Mapper/Builder Strategy &#171; inverted index</title>
		<link>http://www.jakubkorab.net/2009/10/a-better-builder.html/comment-page-1#comment-699</link>
		<dc:creator>Interesting Mapper/Builder Strategy &#171; inverted index</dc:creator>
		<pubDate>Wed, 14 Oct 2009 13:40:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.jakubkorab.net/?p=226#comment-699</guid>
		<description>[...]  October 14, 2009 grwilliamson Leave a comment Go to comments    Jakub has an interesting slant on the problem of mapping objects from one representation into another, without [...]</description>
		<content:encoded><![CDATA[<p>[...]  October 14, 2009 grwilliamson Leave a comment Go to comments    Jakub has an interesting slant on the problem of mapping objects from one representation into another, without [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Graham Williamson</title>
		<link>http://www.jakubkorab.net/2009/10/a-better-builder.html/comment-page-1#comment-697</link>
		<dc:creator>Graham Williamson</dc:creator>
		<pubDate>Wed, 14 Oct 2009 13:34:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.jakubkorab.net/?p=226#comment-697</guid>
		<description>Nice. I like this approach. It provides a very elegant mechanism for mocking, for sure.

I&#039;ve just completed a recent project involving a lot of &quot;mapping&quot; or &quot;translating&quot;. I opted for individual mapper classes due to their reusability across different scenarios - for example the mapping of a particular type that is a member of many different, and quite independent, objects.

In addition, the mapping classes were really pretty big and to have all of this logic in a single class would create a massive class. Not quite a monolithic block of code in a single method, but it would still have the feel of a retro procedural programming treat.

I guess for me I felt that the individual mapper classes were better aligned with the principles of single responsibility, separation of concerns, increased cohesion and reduced coupling, albeit for the cost of class explosion! Each mapper only knew about the input object, the resulting output object, and any child or member objects. It&#039;s also simple to test - something which I did actually do.

Like everything though, it depends on the situation and it&#039;s interesting to have another tool in the bat belt for this. I&#039;ll definitely take this into consideration next time around.</description>
		<content:encoded><![CDATA[<p>Nice. I like this approach. It provides a very elegant mechanism for mocking, for sure.</p>
<p>I&#8217;ve just completed a recent project involving a lot of &#8220;mapping&#8221; or &#8220;translating&#8221;. I opted for individual mapper classes due to their reusability across different scenarios &#8211; for example the mapping of a particular type that is a member of many different, and quite independent, objects.</p>
<p>In addition, the mapping classes were really pretty big and to have all of this logic in a single class would create a massive class. Not quite a monolithic block of code in a single method, but it would still have the feel of a retro procedural programming treat.</p>
<p>I guess for me I felt that the individual mapper classes were better aligned with the principles of single responsibility, separation of concerns, increased cohesion and reduced coupling, albeit for the cost of class explosion! Each mapper only knew about the input object, the resulting output object, and any child or member objects. It&#8217;s also simple to test &#8211; something which I did actually do.</p>
<p>Like everything though, it depends on the situation and it&#8217;s interesting to have another tool in the bat belt for this. I&#8217;ll definitely take this into consideration next time around.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
