<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>OlliN&#039;s</title>
	<atom:link href="http://www.nautsch.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.nautsch.net</link>
	<description>Notizen über Software und Anderes von Oliver Nautsch</description>
	<lastBuildDate>Thu, 20 May 2010 18:50:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Prague</title>
		<link>http://www.nautsch.net/2010/05/20/prague/</link>
		<comments>http://www.nautsch.net/2010/05/20/prague/#comments</comments>
		<pubDate>Thu, 20 May 2010 18:47:57 +0000</pubDate>
		<dc:creator>oliver.nautsch</dc:creator>
				<category><![CDATA[reisen]]></category>

		<guid isPermaLink="false">http://www.nautsch.net/?p=466</guid>
		<description><![CDATA[Two weeks ago we were in the Czech Republic.]]></description>
			<content:encoded><![CDATA[<p>Two weeks ago we were in the <a href="http://en.wikipedia.org/wiki/Czech_Republic">Czech Republic</a>.</p>
<div id="attachment_483" class="wp-caption alignnone" style="width: 310px"><a href="http://www.nautsch.net/wp-content/uploads/DSC_00791.jpg"><img class="size-medium wp-image-483" title="Prague Castle" src="http://www.nautsch.net/wp-content/uploads/DSC_00791-300x199.jpg" border="0/" alt="" width="300" height="199" /></a><p class="wp-caption-text">Prague Castle</p></div>
<p><span id="more-466"></span></p>
<div id="attachment_480" class="wp-caption alignnone" style="width: 209px"><a href="http://www.nautsch.net/wp-content/uploads/DSC_00221.jpg"><img class="size-medium wp-image-480" title="Prag Castle" src="http://www.nautsch.net/wp-content/uploads/DSC_00221-199x300.jpg" border="0/" alt="Prag Castle" width="199" height="300" /></a><p class="wp-caption-text">Prague Castle</p></div>
<div id="attachment_485" class="wp-caption alignnone" style="width: 310px"><a href="http://www.nautsch.net/wp-content/uploads/DSC_0305.jpg"><img class="size-medium wp-image-485" title="Prague Zoo" src="http://www.nautsch.net/wp-content/uploads/DSC_0305-300x199.jpg" border="0" alt="Prague Zoo" width="300" height="199" /></a><p class="wp-caption-text">Prague Zoo</p></div>
<div id="attachment_481" class="wp-caption alignnone" style="width: 209px"><a href="http://www.nautsch.net/wp-content/uploads/DSC_00311.jpg"><img class="size-medium wp-image-481" title="Prague Metro" src="http://www.nautsch.net/wp-content/uploads/DSC_00311-199x300.jpg" border="0/" alt="Prague Metro" width="199" height="300" /></a><p class="wp-caption-text">Prague Metro</p></div>
<div id="attachment_484" class="wp-caption alignnone" style="width: 209px"><a href="http://www.nautsch.net/wp-content/uploads/DSC_0085.jpg"><img class="size-medium wp-image-484" title="Franz Kafka" src="http://www.nautsch.net/wp-content/uploads/DSC_0085-199x300.jpg" border="0" alt="Franz Kafka" width="199" height="300" /></a><p class="wp-caption-text">Franz Kafka</p></div>
<div id="attachment_476" class="wp-caption alignnone" style="width: 235px"><a href="http://www.nautsch.net/wp-content/uploads/20100506_0021.jpg"><img class="size-medium wp-image-476" title="Rudolfinum - Czech Philharmonic Orchestra" src="http://www.nautsch.net/wp-content/uploads/20100506_0021-225x300.jpg" border="0/" alt="Rudolfinum - Czech Philharmonic Orchestra" width="225" height="300" /></a><p class="wp-caption-text">Rudolfinum - Czech Philharmonic Orchestra</p></div>
<div id="attachment_477" class="wp-caption alignnone" style="width: 235px"><a href="http://www.nautsch.net/wp-content/uploads/20100507_0141.jpg"><img class="size-medium wp-image-477" title="Karlštejn" src="http://www.nautsch.net/wp-content/uploads/20100507_0141-225x300.jpg" border="0/" alt="Karlštejn" width="225" height="300" /></a><p class="wp-caption-text">Karlštejn</p></div>
<div id="attachment_478" class="wp-caption alignnone" style="width: 310px"><a href="http://www.nautsch.net/wp-content/uploads/20100507_0651.jpg"><img class="size-medium wp-image-478" title="somewhere between Karlštejn and Prague" src="http://www.nautsch.net/wp-content/uploads/20100507_0651-300x225.jpg" border="0/" alt="somewhere between Karlštejn and Prague" width="300" height="225" /></a><p class="wp-caption-text">somewhere between Karlštejn and Prague</p></div>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.nautsch.net/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.nautsch.net/2010/05/20/prague/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Schloss Hallwyl</title>
		<link>http://www.nautsch.net/2010/04/11/schloss-hallwyl/</link>
		<comments>http://www.nautsch.net/2010/04/11/schloss-hallwyl/#comments</comments>
		<pubDate>Sun, 11 Apr 2010 19:07:45 +0000</pubDate>
		<dc:creator>oliver.nautsch</dc:creator>
				<category><![CDATA[reisen]]></category>

		<guid isPermaLink="false">http://www.nautsch.net/?p=460</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.nautsch.net/wp-content/uploads/20100411_003.jpeg"><img class="alignnone size-full wp-image-461" style="border: 0pt none;" title="20100411_003" src="http://www.nautsch.net/wp-content/uploads/20100411_003.jpeg" alt="" width="400" height="301" /></a></p>
<p><a href="http://www.nautsch.net/wp-content/uploads/20100411_010.jpeg"><img class="alignnone size-full wp-image-462" style="border: 0pt none;" title="20100411_010" src="http://www.nautsch.net/wp-content/uploads/20100411_010.jpeg" alt="" width="400" height="301" /></a></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.nautsch.net/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.nautsch.net/2010/04/11/schloss-hallwyl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>No mouse, No keyboard after upgrading to xorg-server 1.7</title>
		<link>http://www.nautsch.net/2010/04/10/no-mouse-no-keyboard-after-upgrading-to-xorg-server-1-7/</link>
		<comments>http://www.nautsch.net/2010/04/10/no-mouse-no-keyboard-after-upgrading-to-xorg-server-1-7/#comments</comments>
		<pubDate>Sat, 10 Apr 2010 19:53:28 +0000</pubDate>
		<dc:creator>oliver.nautsch</dc:creator>
				<category><![CDATA[gentoo]]></category>

		<guid isPermaLink="false">http://www.nautsch.net/?p=458</guid>
		<description><![CDATA[If the mouse and the keyboard are not working anymore after upgrading the xorg-server, you have probably forgot to rebuild the xorg-drivers. On a gentoo box find the drivers with: qlist -I xorg-drivers Emerge the the drivers on the list. e.g.: emerge -v1 x11-drivers/xf86-input-evdev x11-drivers/nvidia-drivers]]></description>
			<content:encoded><![CDATA[<p>If the mouse and the keyboard are not working anymore after upgrading the xorg-server, you have probably forgot to rebuild the xorg-drivers. On a gentoo box find the drivers with:</p>
<pre>qlist -I xorg-drivers
</pre>
<p>Emerge the the drivers on the list.</p>
<p>e.g.:</p>
<pre>emerge -v1 x11-drivers/xf86-input-evdev x11-drivers/nvidia-drivers
</pre>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.nautsch.net/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.nautsch.net/2010/04/10/no-mouse-no-keyboard-after-upgrading-to-xorg-server-1-7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Compiling qt-copy inside a VM is to slow</title>
		<link>http://www.nautsch.net/2010/03/07/compiling-qt-copy-inside-a-vm-is-to-slow/</link>
		<comments>http://www.nautsch.net/2010/03/07/compiling-qt-copy-inside-a-vm-is-to-slow/#comments</comments>
		<pubDate>Sun, 07 Mar 2010 16:11:54 +0000</pubDate>
		<dc:creator>oliver.nautsch</dc:creator>
				<category><![CDATA[kde]]></category>

		<guid isPermaLink="false">http://www.nautsch.net/?p=455</guid>
		<description><![CDATA[Compiling qt-copy inside a VMWare virtual machine is to slow 1h 21m 49s compared to compiling it directly on my Gentoo box: 38m 18s So I decided to switch from the VM directly to my Gentoo box with a kde-devel user. I used in both cases ./kdesvn-build qt-copy as described in the document  &#8220;Getting Started/Build/kdesvn-build&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>Compiling <a href="http://gitorious.org/+kde-developers/qt/kde-qt">qt-copy</a> inside a VMWare virtual machine is to slow</p>
<blockquote><p>1h 21m 49s</p></blockquote>
<p>compared to compiling it directly on my Gentoo box:</p>
<blockquote><p>38m 18s</p></blockquote>
<p>So I decided to switch from the VM directly to my Gentoo box with a <a href="http://techbase.kde.org/Getting_Started/Build/KDE4">kde-devel</a> user. I used in both cases</p>
<pre>./kdesvn-build qt-copy
</pre>
<p>as described in the document  &#8220;<a href="http://techbase.kde.org/Getting_Started/Build/kdesvn-build#Build">Getting Started/Build/kdesvn-build</a>&#8221; with a clean kde-src directory.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.nautsch.net/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.nautsch.net/2010/03/07/compiling-qt-copy-inside-a-vm-is-to-slow/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New N900 and my plan to sync with Kontact</title>
		<link>http://www.nautsch.net/2010/03/06/new-n900-and-my-plan-to-sync-with-kontact/</link>
		<comments>http://www.nautsch.net/2010/03/06/new-n900-and-my-plan-to-sync-with-kontact/#comments</comments>
		<pubDate>Sat, 06 Mar 2010 09:10:41 +0000</pubDate>
		<dc:creator>oliver.nautsch</dc:creator>
				<category><![CDATA[hardware]]></category>
		<category><![CDATA[kde]]></category>

		<guid isPermaLink="false">http://www.nautsch.net/?p=453</guid>
		<description><![CDATA[I have a new toy &#8211; a Nokia N900 cell phone.  It is a nice gadget. But I miss a easy way to synchronize my contacts, calendars, tasks etc. with KDE&#8217;s Kontact. N900 &#60;-&#62; USB/WLAN &#60;-&#62; Laptop/Kontact Yesterday I ask for a solution to synchronize (at freenode#kontact). The answers are more or less: Setting up [...]]]></description>
			<content:encoded><![CDATA[<p>I have a new toy &#8211; a Nokia N900 cell phone.  It is a nice gadget. But I miss a <strong>easy</strong> way to synchronize my contacts, calendars, tasks etc. with KDE&#8217;s <a href="http://en.wikipedia.org/wiki/Kontact">Kontact</a>.</p>
<pre>N900 &lt;-&gt; USB/WLAN &lt;-&gt; Laptop/Kontact</pre>
<p>Yesterday I ask for a solution to synchronize (at freenode#kontact). The answers are more or less: Setting up a Groupware-Solution (e.g. <a href="http://en.wikipedia.org/wiki/Horde_(software)">Horde</a>) &#8211; sync the phone with this server &#8211; sync Kontact with the server.</p>
<p>But I think there must be easier solution for &#8220;normal&#8221; users without setting up such a server. And now I have a new<strong> long-term</strong> pet project. <img src='http://www.nautsch.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I found a few tools that I could possibly use (The list is not exhaustive.):</p>
<ul>
<li><a href="http://syncevolution.org/">SyncEvolution</a> (N900/<a href="http://maemo.org/">Maemo</a> side)</li>
<li>the build-in synchronization &#8211; ? (N900)</li>
<li><a href="http://saschpe.wordpress.com/2009/06/02/gsoc-week-1-2-wrap-up/">Akonadi SyncML Agent</a> (Kontact side)</li>
</ul>
<p>But at first I have to bootstrap my C++, Qt and KDE-programming knowledge. My plan is to help kde-pim a little bit to become familiar with the whole environment. At the moment I&#8217;m setting up a KDE development environment. It runs in a VM. If I have more experience, I will run it directly on my gentoo os.</p>
<p>So, qt-copy is compiling&#8230; <img src='http://www.nautsch.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Btw. I finished the go-lang tutorial. I like the language. But at the moment I have no project to use it.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.nautsch.net/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.nautsch.net/2010/03/06/new-n900-and-my-plan-to-sync-with-kontact/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>go lang</title>
		<link>http://www.nautsch.net/2010/01/31/go-lang/</link>
		<comments>http://www.nautsch.net/2010/01/31/go-lang/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 10:26:52 +0000</pubDate>
		<dc:creator>oliver.nautsch</dc:creator>
				<category><![CDATA[golang]]></category>

		<guid isPermaLink="false">http://www.nautsch.net/?p=447</guid>
		<description><![CDATA[Yesterday I decided to learn a new programming language. My choice was the programming language &#8220;go&#8220;. The reason is the announcement that this language should be included in the gcc. So I will report the next time a little bit about my experiences. The installation was completed thanks to a good description in 15 minutes. [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I decided to learn a new programming language. My choice was the programming language &#8220;<a href="http://golang.org/">go</a>&#8220;. The reason is the <a href="http://lwn.net/Articles/371466/">announcement</a> that this language should be included in the <a href="http://gcc.gnu.org/">gcc</a>. So I will report the next time a little bit about my experiences.</p>
<p>The installation was completed thanks to a good <a href="http://golang.org/doc/install.html">description</a> in 15 minutes. One problem I had when compiling. You have the locale set to &#8220;en_US&#8221; during the compilation:</p>
<blockquote><p><code>$ cd $GOROOT/src<br />
$ LANG=en_US ./all.bash</code></p></blockquote>
<p>5 minutes later, the &#8220;hello world&#8221; ran.</p>
<p>In the directory <code>$GOROOT/misc/kate</code>,  a file <code>go.xml</code> can be found for the syntax highlighting in <a href="http://www.kate-editor.org/">kate</a>. This file must be copied into the directory <code>~/.kde4/share/apps/katepart/syntax/</code>.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.nautsch.net/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.nautsch.net/2010/01/31/go-lang/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Help Krita..</title>
		<link>http://www.nautsch.net/2009/12/04/help-krita/</link>
		<comments>http://www.nautsch.net/2009/12/04/help-krita/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 17:38:47 +0000</pubDate>
		<dc:creator>oliver.nautsch</dc:creator>
				<category><![CDATA[kde]]></category>

		<guid isPermaLink="false">http://www.nautsch.net/?p=440</guid>
		<description><![CDATA[&#8230; and donate. I did it.]]></description>
			<content:encoded><![CDATA[<p>&#8230; and <a href="http://pledgie.com/campaigns/7221">donate</a>. I did it. <img src='http://www.nautsch.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.nautsch.net/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.nautsch.net/2009/12/04/help-krita/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gesetz von Demeter, Unit Tests und der zweite Programmierer</title>
		<link>http://www.nautsch.net/2009/11/21/gesetz-von-demeter-unit-tests-und-der-zweite-programmierer/</link>
		<comments>http://www.nautsch.net/2009/11/21/gesetz-von-demeter-unit-tests-und-der-zweite-programmierer/#comments</comments>
		<pubDate>Sat, 21 Nov 2009 10:43:33 +0000</pubDate>
		<dc:creator>oliver.nautsch</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://www.nautsch.net/?p=423</guid>
		<description><![CDATA[In meinem letzten Post habe ich beschrieben, das Delegation für den Benutzer einer Klasse angenehm ist und das wir dies auch im realen Leben schätzen. Heute möchte ich kurz beschreiben wie sich das Einhalten des Gesetzes von Demeter auf das Schreiben von Unit-Tests und das Benutzen meiner Implementierungen auswirkt. Dazu habe ich das Modell um [...]]]></description>
			<content:encoded><![CDATA[<p>In meinem <a href="http://www.nautsch.net/2009/11/19/gesetz-von-demeter-im-alltag/">letzten Post</a> habe ich beschrieben, das Delegation für den Benutzer einer Klasse angenehm ist und das wir dies auch im realen Leben schätzen. Heute möchte ich kurz beschreiben wie sich das Einhalten des <a href="http://de.wikipedia.org/wiki/Law_of_Demeter">Gesetzes von Demeter</a> auf das Schreiben von Unit-Tests und das Benutzen meiner Implementierungen auswirkt. Dazu habe ich das Modell um Implementierungen erweitert:</p>
<p><img class="size-full wp-image-424 alignnone" title="lod_overview_1" src="http://www.nautsch.net/wp-content/uploads/lod_overview_1.png" alt="lod overview 1" width="637" height="340" /></p>
<p><span id="more-423"></span>Am Beispiel von CityBike möchte ich erklären, dass die Implementierung der Unit-Test&#8217;s jetzt ganz einfach geht. Wir haben also die leere Implementierung der Klasse:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p423code7'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4237"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code" id="p423code7"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> CityBike <span style="color: #000000; font-weight: bold;">implements</span> WithBasket <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> Basket basket<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> CityBike<span style="color: #009900;">&#40;</span>Basket basket<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> addElement <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aelement+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Element</span></a> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> Basket getBasket <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Alle Implementierungen sind leer, da wir ja im Sinne von <a href="http://de.wikipedia.org/wiki/Testgetriebene_Entwicklung">Test-Driven Development</a> (TDD) zuerst unsere Tests schreiben und erst danach die Implementierung. Hier also die <a href="http://www.junit.org/">JUnit4</a>-Testklasse:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p423code8'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4238"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
</pre></td><td class="code" id="p423code8"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.junit.Before</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.junit.Test</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">static</span> org.<span style="color: #006633;">junit</span>.<span style="color: #000000; font-weight: bold;">Assert</span>.<span style="color: #339933;">*;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">static</span> org.<span style="color: #006633;">mockito</span>.<span style="color: #006633;">Mockito</span>.<span style="color: #339933;">*;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> CityBikeTest <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> Basket basket<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> CityBike cityBike<span style="color: #339933;">;</span>
&nbsp;
    @Before
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setUp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        basket <span style="color: #339933;">=</span> mock<span style="color: #009900;">&#40;</span>Basket.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        cityBike <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> CityBike<span style="color: #009900;">&#40;</span>basket<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Test<span style="color: #009900;">&#40;</span>expected<span style="color: #339933;">=</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aillegalargumentexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">IllegalArgumentException</span></a>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> shouldNotCreateWithNullAsBasket<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">new</span> CityBike<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Test
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> shouldDelegateAddElementToBasket<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aelement+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Element</span></a> e1 <span style="color: #339933;">=</span> mock<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aelement+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Element</span></a>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">//</span>
        cityBike.<span style="color: #006633;">addElement</span><span style="color: #009900;">&#40;</span>e1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">//</span>
        verify<span style="color: #009900;">&#40;</span>basket<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>e1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Test
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> shouldReturnBasket<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        assertEquals<span style="color: #009900;">&#40;</span>basket, cityBike.<span style="color: #006633;">getBasket</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Alle 3 Tests melden einen Fehler. Also ändern wir die Implementierung so, dass die Tests funktionieren:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p423code9'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4239"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code" id="p423code9"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> CityBike <span style="color: #000000; font-weight: bold;">implements</span> WithBasket <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> Basket basket<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> CityBike<span style="color: #009900;">&#40;</span>Basket basket<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">==</span> basket<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aillegalargumentexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">IllegalArgumentException</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;null as basket not allowed&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">basket</span> <span style="color: #339933;">=</span> basket<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> addElement <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aelement+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Element</span></a> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">basket</span>.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> Basket getBasket <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">basket</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Alle Tests funktionieren. <img src='http://www.nautsch.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  (Die Implementierung und Tests für SimpleBasket und SimpleElement lasse ich hier im Text mal weg, damit es nicht zu unübersichtlich wird.) Damit haben wir als Programmierer von CityBike mal alles gemacht</p>
<p>Jetzt kommt ein zweiter Programmierer und möchte unsere Klassen benutzen. Es wird eine Person implementiert, die mit dem Fahrrad fahren soll. Allerdings muss dieser Fahrer seine Umhängetasche in den Korb (Basket) legen, bevor er losfahren darf. Natürlich sollte auch der zweite Programmierer seine Klassen &#8220;Fahrer&#8221; und &#8220;Tasche&#8221; testen. Hier die fertigen Implementierungen:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p423code10'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p42310"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
</pre></td><td class="code" id="p423code10"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Fahrer <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> Tasche tasche<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> CityBike cityBike<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> Fahrer<span style="color: #009900;">&#40;</span>Tasche tasche, CityBike cityBike<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">==</span> tasche<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aillegalargumentexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">IllegalArgumentException</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;null as tasche not allowed&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">tasche</span> <span style="color: #339933;">=</span> tasche<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">==</span> cityBike<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aillegalargumentexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">IllegalArgumentException</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;null as cityBike not allowed&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">cityBike</span> <span style="color: #339933;">=</span> cityBike<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">void</span> losfahren<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">cityBike</span>.<span style="color: #006633;">addElement</span><span style="color: #009900;">&#40;</span>tasche<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// aufsteigen</span>
        <span style="color: #666666; font-style: italic;">// nach rechts und links schauen</span>
        <span style="color: #666666; font-style: italic;">// anfangen in die Pedalen zu treten</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Tasche <span style="color: #000000; font-weight: bold;">implements</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aelement+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Element</span></a> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> getWeight<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #cc66cc;">12</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.junit.Before</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.junit.Test</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">static</span> org.<span style="color: #006633;">mockito</span>.<span style="color: #006633;">Mockito</span>.<span style="color: #339933;">*;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> FahrerTest <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> Tasche tasche<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> CityBike cityBike<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> Fahrer fahrer<span style="color: #339933;">;</span>
&nbsp;
    @Before
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setUp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">tasche</span> <span style="color: #339933;">=</span> mock<span style="color: #009900;">&#40;</span>Tasche.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">cityBike</span> <span style="color: #339933;">=</span> mock<span style="color: #009900;">&#40;</span>CityBike.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">fahrer</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Fahrer<span style="color: #009900;">&#40;</span>tasche, cityBike<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Test
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> shouldAddTascheInKorb<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">//</span>
        fahrer.<span style="color: #006633;">losfahren</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">//</span>
        verify<span style="color: #009900;">&#40;</span>cityBike<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">addElement</span><span style="color: #009900;">&#40;</span>tasche<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Was passiert, wenn wir die Methode addElement(Element e) aus WithBasket und CityBike rausnehmen. Jeder der dann WithBasket, CityBike oder andere Subklassen von WithBasket benutzt muss dann den Wege über getBasket().add(Element e) gehen. Die Methode losfahren in Fahrer sieht dann so aus:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p423code11'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p42311"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p423code11"><pre class="java" style="font-family:monospace;">    <span style="color: #000066; font-weight: bold;">void</span> losfahren<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">cityBike</span>.<span style="color: #006633;">getBasket</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>tasche<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// aufsteigen</span>
        <span style="color: #666666; font-style: italic;">// nach rechts und links schauen</span>
        <span style="color: #666666; font-style: italic;">// anfangen in die Pedalen zu treten</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Aber nicht nur das wir jetzt in X Klassen dieses getBasket().add(tasche) stehen haben. Wir machen den Benutzern unserer Klasse auch noch das Testen schwieriger:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p423code12'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p42312"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
</pre></td><td class="code" id="p423code12"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.junit.Before</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.junit.Test</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">static</span> org.<span style="color: #006633;">mockito</span>.<span style="color: #006633;">Mockito</span>.<span style="color: #339933;">*;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> FahrerTest <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> Tasche tasche<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> CityBike cityBike<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> Basket basket<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> Fahrer fahrer<span style="color: #339933;">;</span>
&nbsp;
    @Before
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setUp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">tasche</span> <span style="color: #339933;">=</span> mock<span style="color: #009900;">&#40;</span>Tasche.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">cityBike</span> <span style="color: #339933;">=</span> mock<span style="color: #009900;">&#40;</span>CityBike.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">basket</span> <span style="color: #339933;">=</span> mock<span style="color: #009900;">&#40;</span>Basket.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">fahrer</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Fahrer<span style="color: #009900;">&#40;</span>tasche, cityBike<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Test
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> shouldAddTascheInKorb<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        when<span style="color: #009900;">&#40;</span>cityBike.<span style="color: #006633;">getBasket</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">thenReturn</span><span style="color: #009900;">&#40;</span>basket<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">//</span>
&nbsp;
        fahrer.<span style="color: #006633;">losfahren</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">//</span>
&nbsp;
        verify<span style="color: #009900;">&#40;</span>basket<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>tasche<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Wir haben eine zusätzliche Membervariable basket im Test und der Test muss noch Vorbereiten das auf cityBike auch wirklich ein Basket geliefert wird. Und hier haben wir nur eine Verschachtelungstiefe. Man denke sich mal aus wie es aussieht wenn wir folgende Situation haben: <code>A.getB().getC().getD().add(E e)</code>. Und jetzt stelle sich der Leser noch vor, dass das ganze Konsequent in der ganzen Applikation so gemacht wird. Irgendwann sind die Tests so aufwendig und kompliziert, dass kein Entwickler mehr Tests schreibt, weil einfach keine Zeit ist. Wenn dagegen immer das Law of Demeter eingehalten wird, dann sind die Tests kurz und einfach.</p>
<p>Schlusswort:</p>
<p>Ich habe hier <a href="http://mockito.org/">Mockito</a> verwendet um die Mock-Objekte zu schreiben. Eine wirkliche Empfehlung von meiner Seite. Diese Bibo ist der Hammer. Wirklich schnell zu lernen und eine wunderschöne API. Gratulation an die Entwickler zu diesem tollen Stück Software.</p>
<p>Schönes Wochenende!</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.nautsch.net/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.nautsch.net/2009/11/21/gesetz-von-demeter-unit-tests-und-der-zweite-programmierer/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Gesetz von Demeter im Alltag</title>
		<link>http://www.nautsch.net/2009/11/19/gesetz-von-demeter-im-alltag/</link>
		<comments>http://www.nautsch.net/2009/11/19/gesetz-von-demeter-im-alltag/#comments</comments>
		<pubDate>Thu, 19 Nov 2009 20:55:21 +0000</pubDate>
		<dc:creator>oliver.nautsch</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[leute]]></category>

		<guid isPermaLink="false">http://www.nautsch.net/?p=409</guid>
		<description><![CDATA[In den letzten zwei Monaten hatte ich im Umfeld der Software-Entwicklung sehr viel dieser &#8220;AHA&#8221;-Effekte. Da das Gehirn neue Erkenntnisse mit dem Ausschütten von Glückshormonen belohnt, war es eine sehr gute Zeit für mich. Als heute  morgen alle noch bei Kaffee in unserem Pausenraum sassen, habe ich ein speziellen Teil unseres Domain Modells an die [...]]]></description>
			<content:encoded><![CDATA[<p>In den letzten zwei Monaten hatte ich im Umfeld der Software-Entwicklung sehr viel dieser &#8220;AHA&#8221;-Effekte. Da das Gehirn neue Erkenntnisse mit dem Ausschütten von Glückshormonen belohnt, war es eine sehr gute Zeit für mich. <img src='http://www.nautsch.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Als heute  morgen alle noch bei Kaffee in unserem Pausenraum sassen, habe ich ein speziellen Teil unseres Domain Modells an die dort hängende Tafel gemalt. Ich wollte allen mitteilen, auf welch schönes Design wir gestern für einen Teil unseres Domain Modells gekommen waren. Insbesondere wollte ich auch aufzeigen, wie elegant eine Lösung werden kann, wenn man sich an das <a href="http://de.wikipedia.org/wiki/Gesetz_von_Demeter">Gesetzt von Demeter</a> hält. Dabei haben Jan und ich nicht mal an das Gesetz gedacht, als wir die Schnittstellen definiert haben. Es ist sozusagen &#8220;einfach entstanden&#8221;.</p>
<p>Hier ein leicht abgeändertes Beispiel:</p>
<p><img class="size-full wp-image-411  alignnone" title="law_of_demeter-1" src="http://www.nautsch.net/wp-content/uploads/law_of_demeter-1.png" alt="lod 1" /></p>
<p><span id="more-409"></span>Wir haben also ein Interface welches aussagt, dass ein Typ welches dieses Interface implementiert eine Has-A-Beziehung zu Basket hat. Ein WithBasket-Object hat also immer einen Basket. Ausserdem kann ein Basket eine Menge (0 bis n ) Elemente beinhalten. Nun machen wir mal zwei Methoden hinzu:</p>
<p><img class="size-full wp-image-413  alignnone" title="law_of_demeter-2" src="http://www.nautsch.net/wp-content/uploads/law_of_demeter-2.png" alt="lod 2"  /></p>
<p>Die Diskussion entbrannte nun an der Methode <code>addElement(Element e)</code> in WithBasket. Eine Implementierung von WithBasket muss also diesen Aufruf an Basket delegieren. Und dieser Punkt war einigen Kollegen nicht geheuer bzw. wurde abgelehnt, u.a. mit der Begründung, dass ja der Typ WithBasket nicht für die Verwaltung von Elementen zuständig ist. Besser sei auf WithBasket eine Methode &#8220;<code>public Basket getBasket()</code>&#8221; zu implementieren, <code>void addElement(Element e)</code> wegzunehmen und der Benutzer von WithBasket kann dann auf dem Basket die gewünschten Operationen ausführen. In einem Client von WithBasket würde also folgender Code stehen:</p>
<p><code>myObjectWithBasket.getBasket().add(myElement);</code></p>
<p>Dies bricht das Gesetz von Demeter.</p>
<p>Nun habe ich in der Mittagspause nachgedacht und nach Beispielen aus dem realen Leben gesucht. Als Erstes ist mir ein Theaterbesuch in der ehemaligen DDR eingefallen. Dort habe ich mal Folgendes erlebt:</p>
<blockquote><p>Vor der Garderobe des Theaters stand eine Angestellte des Theaters die offensichtlich für die Garderobe zuständig war. Als wir nun unsere Jacken abgeben wollten, zeigte sie mit dem Finger auf die Kleiderhaken und wir mussten nach hinten gehen und unsere Sachen selber aufhängen.</p></blockquote>
<p>Es ist richtig, dass es nicht die Verantwortlichkeit der Garderobenfrau war, unsere Kleider die ganze Vorstellung lang zu halten. Trotzdem empfindet man dies doch als komisch. Ich bin jedes mal dankbar, wenn mir die Jacke abgenommen und an die Kleiderhaken gehängt wird. Dieses Muster findet man sehr oft vor. Ein weiteres Beispiel die die Essenbestellung im Restaurant. (Gast -&gt; Bedienung -&gt; Koch).</p>
<p>Ein weiters Beispiel ist die Rezeption im Technopark Zürich. Die Rezeption hat auch einen Kopierer und wenn man möchte, kann man dort auch Sachen kopieren lassen. Man gibt ein Blatt ab, die Frau an der Rezeption nimmt das Blatt, legt es auf den Kopierer und drückt den grünen Knopf. Es ist so viel angenehmer, als erst selbst hinter die Rezeption an den Kopierer gehen zu müssen. Was passiert aber, wenn ich den Kopierer viel besser bedienen kann, als die Frau an der Rezeption? Ich kenne das Teil und weiss, wie man die Graustufen einstellt und wie man verkleinert. In solch einem Fall wäre es eventuell doch nötig an den Kopierer heranzukommen.</p>
<p>Um wieder zum Basket-Beispiel zurückzukommen. Was macht man, wenn man nun Basket in einem <a href="http://de.wikipedia.org/wiki/GUI">GUI</a> darstellen möchte und nur WithBasket hat?</p>
<p><img class="size-full wp-image-415  alignnone" title="law_of_demeter-3" src="http://www.nautsch.net/wp-content/uploads/law_of_demeter-3.png" alt="lod 3"  /></p>
<p>Für die Darstellung von Basket breche ich nun die Kapselung. Nicht unbedingt 100% Law of Demeter aber pragmatisch. Oder?</p>
<p>Trotzdem stelle ich die wichtigen Operationen von Basket am WithBasket zur Verfügung, damit im Domain-Model immer über dieses gegangen werden kann. Und wenn ich getBasket weglassen kann, dann mache ich es auch. Schlussendlich entscheidet der fachliche Kontext in solch einem Fall.</p>
<p>Wie einfach die Unit-Tests dann auf einmal zu schreiben sind, kommt vielleicht ein anderes Mal. Heute bin ich zu müde&#8230;</p>
<p>Gute Nacht</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.nautsch.net/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.nautsch.net/2009/11/19/gesetz-von-demeter-im-alltag/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Engstligenalp &#8211; Tschingellochtighorn</title>
		<link>http://www.nautsch.net/2009/10/15/engstligenalp-tschingellochtighorn/</link>
		<comments>http://www.nautsch.net/2009/10/15/engstligenalp-tschingellochtighorn/#comments</comments>
		<pubDate>Thu, 15 Oct 2009 12:03:07 +0000</pubDate>
		<dc:creator>oliver.nautsch</dc:creator>
				<category><![CDATA[leute]]></category>
		<category><![CDATA[wandern]]></category>

		<guid isPermaLink="false">http://www.nautsch.net/?p=398</guid>
		<description><![CDATA[Letztes Wochenende haben uns Freunde in Adelboden besucht und wir sind zusammen mit der Seilbahn auf die Engstligenalp gefahren. Oben sind wir dann auf dem Ärtelegrad Richtung Tschingellochtighorn gegangen. Das steilere Stück bis zum Engstligengrat bin ich dann noch allein hochgestiegen. Ich konnte dann die Stelle sehen, wo ich vor einem Jahr die Rote Chumme [...]]]></description>
			<content:encoded><![CDATA[<p>Letztes Wochenende haben uns Freunde in Adelboden besucht und wir sind zusammen mit der Seilbahn auf die <a href="http://de.wikipedia.org/wiki/Engstligenalp">Engstligenalp</a> gefahren.</p>
<div id="attachment_401" class="wp-caption alignnone" style="width: 310px"><a href="http://www.nautsch.net/wp-content/uploads/dsc_0176.jpg"><img class="size-medium wp-image-401" title="Engstligenalp mit Wildstrubel" src="http://www.nautsch.net/wp-content/uploads/dsc_0176-300x199.jpg" alt="Engstligenalp mit Wildstrubel" width="300" height="199" /></a><p class="wp-caption-text">Engstligenalp mit Wildstrubel</p></div>
<p><span id="more-398"></span></p>
<p>Oben sind wir dann auf dem Ärtelegrad Richtung <a href="http://de.wikipedia.org/wiki/Tschingellochtighorn">Tschingellochtighorn</a> gegangen.</p>
<div id="attachment_400" class="wp-caption alignnone" style="width: 310px"><a href="http://www.nautsch.net/wp-content/uploads/dsc_0172.jpg"><img class="size-medium wp-image-400" title="Tschingellochtighorn" src="http://www.nautsch.net/wp-content/uploads/dsc_0172-300x199.jpg" alt="Tschingellochtighorn" width="300" height="199" /></a><p class="wp-caption-text">Tschingellochtighorn</p></div>
<p>Das steilere Stück bis zum Engstligengrat bin ich dann noch allein hochgestiegen. Ich konnte dann die Stelle sehen, wo ich vor einem Jahr die Rote Chumme hochgekommen bin.</p>
<div id="attachment_403" class="wp-caption alignnone" style="width: 209px"><a href="http://www.nautsch.net/wp-content/uploads/dsc_02641.jpg"><img class="size-medium wp-image-403" title="dsc_0264" src="http://www.nautsch.net/wp-content/uploads/dsc_02641-199x300.jpg" alt="Entschligegrat mit Blick auf Rote Totz" width="199" height="300" /></a><p class="wp-caption-text">Engstligengrat mit Blick auf Rote Totz</p></div>
<p>Was für ein schöner Tag <img src='http://www.nautsch.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>______<br />
Update 2009-10-16:</p>
<p>Hier noch die <a href="http://www.nautsch.net/wp-content/uploads/2009-10-11.kmz">Engstligenalp – Tschingellochtighorn</a> Wegmarkierung für Google Earth.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.nautsch.net/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.nautsch.net/2009/10/15/engstligenalp-tschingellochtighorn/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
