<?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 &#187; java</title>
	<atom:link href="http://www.nautsch.net/category/java/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>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>
]]></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>
]]></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>Spring Greenpages mit Teneo</title>
		<link>http://www.nautsch.net/2009/09/29/spring-greenpages-mit-teneo/</link>
		<comments>http://www.nautsch.net/2009/09/29/spring-greenpages-mit-teneo/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 20:07:35 +0000</pubDate>
		<dc:creator>oliver.nautsch</dc:creator>
				<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.nautsch.net/?p=395</guid>
		<description><![CDATA[Beim SpringSource® dm Server™ ist ein Beispiel dabei, welches Greenpages heisst. Vor ein paar Wochen durfte ich auf Arbeit mal ausprobieren, ob Teneo mit dem dm-Server läuft. Also habe ich mir das Beispiel von SpringSource geschnappt und die Sache angeschaut. Es hat funktioniert! Leider habe ich erst heute Zeit gefunden, den Source auf bitbucket zu [...]]]></description>
			<content:encoded><![CDATA[<p>Beim <a href="http://www.springsource.org/dmserver">SpringSource® dm Server™</a> ist ein Beispiel dabei, welches Greenpages heisst. Vor ein paar Wochen durfte ich auf <a href="http://www.inventage.com">Arbeit</a> mal ausprobieren, ob <a href="http://www.eclipse.org/modeling/emf/?project=teneo">Teneo</a> mit dem dm-Server läuft.  Also habe ich mir das Beispiel von SpringSource geschnappt und die Sache angeschaut.</p>
<p>Es hat funktioniert!</p>
<p>Leider habe ich erst heute Zeit gefunden, den Source auf <a href="http://bitbucket.org/olivernautsch/spring-greenpages-with-teneo/">bitbucket</a> zu stellen. Es hat noch hässliche Sachen drin.  Mir ist es in der Klasse <a href="http://bitbucket.org/olivernautsch/spring-greenpages-with-teneo/src/tip/greenpages.teneo/src/main/java/greenpages/teneo/TeneoDirectory.java">TeneoDirectory</a> zum Beispiel nicht gelungen, die Transaktionen deklartiv einzubauen. Ich hole jetzt von der EntityManagerFactory einen EntityManager und von dort die Transaktion. Anders habe ich es einfach nicht hinbekommen&#8230; und irgendwann war die Zeit zu Ende.</p>
<p>Wenn jemand eine andere Lösung hat, bitte unbedingt melden.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nautsch.net/2009/09/29/spring-greenpages-mit-teneo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Repository von SpringSource</title>
		<link>http://www.nautsch.net/2009/08/19/repository-von-springsource/</link>
		<comments>http://www.nautsch.net/2009/08/19/repository-von-springsource/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 15:24:42 +0000</pubDate>
		<dc:creator>oliver.nautsch</dc:creator>
				<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.nautsch.net/?p=380</guid>
		<description><![CDATA[Bei meinem letzten Eintrag habe ich noch ein S3-Repository von SpringSource für das Auflösen der Abhängigkeiten zum SpringFramework 3.0.0.M4 benutzt. Ich habe noch einen Ort gefunden in dem die Jar&#8217;s liegen: SpringSource Enterprise Bundle Repository Für OSGi-Liebhaber ist es sicherlich nett, dass die Jar&#8217;s dort alle OSGi-ready sind.]]></description>
			<content:encoded><![CDATA[<p>Bei meinem letzten Eintrag habe ich noch ein S3-Repository von SpringSource für das Auflösen der Abhängigkeiten zum SpringFramework 3.0.0.M4 benutzt. Ich habe noch einen Ort gefunden in dem die Jar&#8217;s liegen:</p>
<p><a href="http://www.springsource.com/repository/app/">SpringSource Enterprise Bundle Repository</a></p>
<p>Für <a href="http://de.wikipedia.org/wiki/OSGi">OSGi</a>-Liebhaber ist es sicherlich nett, dass die Jar&#8217;s dort alle OSGi-ready sind.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nautsch.net/2009/08/19/repository-von-springsource/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Netbeans, Ivy und Spring 3.0.0M4</title>
		<link>http://www.nautsch.net/2009/08/11/netbeans-ivy-und-spring-3-0-0m4/</link>
		<comments>http://www.nautsch.net/2009/08/11/netbeans-ivy-und-spring-3-0-0m4/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 20:35:52 +0000</pubDate>
		<dc:creator>oliver.nautsch</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[netbeans]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://www.nautsch.net/?p=357</guid>
		<description><![CDATA[Ich programmiere gerade eine kleine Web-Applikation und möchte dazu die neuen REST-Features vom Spring-Framework benutzen. Bis gestern habe ich mir dazu in Netbeans ein Webprojekt gebaut und dann ganz artig alle notwendigen Bibos von Hand dem Projekt hinzugefügt. Gestern wurde nun der Milestone 4 von Spring 3.0.0 veröffentlicht und ich wollte mir nicht noch einmal [...]]]></description>
			<content:encoded><![CDATA[<p>Ich programmiere gerade eine kleine Web-Applikation und möchte dazu die neuen <a href="http://blog.springsource.com/2009/03/08/rest-in-spring-3-mvc/">REST-Features</a> vom <a href="http://www.springsource.org/">Spring-Framework</a> benutzen. Bis gestern habe ich mir dazu in Netbeans ein Webprojekt gebaut und dann ganz artig alle notwendigen Bibos von Hand dem Projekt hinzugefügt. Gestern wurde nun der Milestone 4 von Spring 3.0.0 veröffentlicht und ich wollte mir nicht noch einmal die Arbeit machen.<br />
<span id="more-357"></span><br />
Also musste ein Tool her, welches mir alle notwendigen Jar&#8217;s auflösen kann und in mein Projekt einhängt. Da ich nicht so ein rechter Fan von <a href="http://ant.apache.org/ivy/">Maven</a> bin, habe ich wieder einmal die Gelegenheit genutzt und <a href="http://ant.apache.org/ivy/">Ivy</a> ausprobiert. Als IDE verwende ich <a href="http://www.netbeans.org/">Netbeans</a> &#8211; also muss ein Plugin für Netbeans her, welches mir die Arbeit mit Ivy innerhalb der IDE vereinfacht. Also schnell mal bei <a href="http://code.google.com/p/ivybeans/">ivybeans</a> vorbeigeschaut. Version 1.1 unterstützt jetzt auch Webprojekte &#8211; Schick! Also schnell das Plugin installiert und ein Repository gesucht in welchem die 3.0.0M4 Version von Spring liegt. Nach ein wenig Suchen habe ich dann herausgefunden, dass es ein Spring-eigenes Repository in <a href="http://aws.amazon.com/s3/">Amazon S3</a> gibt (<a href="http://s3browse.com/explore/maven.springframework.org/milestone/org/springframework/spring-webmvc/3.0.0.M4/">S3Browse</a> ist übrigens ein guter Browser für S3).</p>
<p>Dann habe ich mir noch die folgenden zwei Dateien für die Konfiguration von Ivy im Projektverzeichnis meines Webprojektes angelegt:</p>
<p><a href="http://www.nautsch.net/wp-content/uploads/ivy-configfiles-location.png"><img class="alignnone size-medium wp-image-370" title="Ablageort der Konfigurationsdateien von Ivy" src="http://www.nautsch.net/wp-content/uploads/ivy-configfiles-location-224x300.png" alt="Ablageort der Konfigurationsdateien von Ivy" width="224" height="300" /></a></p>
<p>Hier der Inhalt der Dateien:</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="left2">Download <a href="http://www.nautsch.net/wp-content/plugins/wp-codebox/wp-codebox.php?p=357&amp;download=ivy.xml">ivy.xml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p35715"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code" id="p357code15"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ivy-module</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;2.0&quot;</span></span>
<span style="color: #009900;">            <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span>
<span style="color: #009900;">            <span style="color: #000066;">xsi:noNamespaceSchemaLocation</span>=</span>
<span style="color: #009900;">                   <span style="color: #ff0000;">&quot;http://ant.apache.org/ivy/schemas/ivy.xsd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;info</span> <span style="color: #000066;">module</span>=<span style="color: #ff0000;">&quot;WebApplication2&quot;</span> <span style="color: #000066;">organisation</span>=<span style="color: #ff0000;">&quot;WebApplication2&quot;</span> <span style="color: #000066;">revision</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configurations<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;conf</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;compile&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;conf</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;runtime&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;conf</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;compile-test&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;conf</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;runtime-test&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configurations<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependencies<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency</span> <span style="color: #000066;">org</span>=<span style="color: #ff0000;">&quot;org.springframework&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;spring-webmvc&quot;</span> <span style="color: #000066;">rev</span>=<span style="color: #ff0000;">&quot;3.0.0.M4&quot;</span> <span style="color: #000066;">conf</span>=<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependencies<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ivy-module<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>


<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="left2">Download <a href="http://www.nautsch.net/wp-content/plugins/wp-codebox/wp-codebox.php?p=357&amp;download=ivysettings.xml">ivysettings.xml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p35716"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p357code16"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ivysettings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;settings</span> <span style="color: #000066;">defaultResolver</span>=<span style="color: #ff0000;">&quot;chained&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resolvers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;chain</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;chained&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ibiblio</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;maven2&quot;</span> <span style="color: #000066;">m2compatible</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ibiblio</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;s3.maven.springframework.org&quot;</span> <span style="color: #000066;">m2compatible</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">root</span>=<span style="color: #ff0000;">&quot;http://s3.amazonaws.com/maven.springframework.org/milestone/&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/chain<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/resolvers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ivysettings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Dann im Projekt Ivy aktivieren. Dazu mit der rechten Maustaste auf das Projekt und in den Ivy-Einstellungen das Häkchen machen und die zwei Dateien auswählen:</p>
<p><a href="http://www.nautsch.net/wp-content/uploads/ivy-activation-netbeans.png"><img class="alignnone size-medium wp-image-365" title="Ivy in Netbeans aktivieren" src="http://www.nautsch.net/wp-content/uploads/ivy-activation-netbeans-300x142.png" alt="Ivy in Netbeans aktivieren" width="300" height="142" /></a></p>
<p>Dann noch das Projekt zwingen sich die Jars zu holen:</p>
<p><a href="http://www.nautsch.net/wp-content/uploads/ivy-force-resolve.png"><img class="alignnone size-medium wp-image-366" title="Force Resolve" src="http://www.nautsch.net/wp-content/uploads/ivy-force-resolve-179x300.png" alt="Force Resolve" width="179" height="300" /></a></p>
<p>Und siehe da&#8230; alle Jar&#8217;s und Sourcen (wenn im Repository) sind da:</p>
<p><a href="http://www.nautsch.net/wp-content/uploads/ivy-resolved-jars.png"><img class="alignnone size-medium wp-image-367" title="Mit Ivy geholte Abhängigkeiten (Jar's und Sourcen)" src="http://www.nautsch.net/wp-content/uploads/ivy-resolved-jars-243x300.png" alt="Mit Ivy geholte Abhängigkeiten (Jar's und Sourcen)" width="243" height="300" /></a></p>
<p>Mit der rechten Maustaste kann man nun ganz einfach die Abhängigkeiten entfernen, die man nicht braucht.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nautsch.net/2009/08/11/netbeans-ivy-und-spring-3-0-0m4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Swing und Netbeans RCP in Döbeln</title>
		<link>http://www.nautsch.net/2009/06/09/swing-und-netbeans-rcp-in-dobeln/</link>
		<comments>http://www.nautsch.net/2009/06/09/swing-und-netbeans-rcp-in-dobeln/#comments</comments>
		<pubDate>Tue, 09 Jun 2009 12:18:36 +0000</pubDate>
		<dc:creator>oliver.nautsch</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[reisen]]></category>

		<guid isPermaLink="false">http://www.nautsch.net/?p=335</guid>
		<description><![CDATA[Tagebucheintrag: Letzte Woche war ich für einen Tag bei einem Kunden in Döbeln (Sachsen). Thema des Workshops war ob einen nackten Swing-Client oder eine RCP-Applikation mit Netbeans bauen.  Schlussendlich haben mehr Argumente dafür gesprochen einen Swing-Client zu bauen.]]></description>
			<content:encoded><![CDATA[<p>Tagebucheintrag:</p>
<p>Letzte Woche war ich für einen Tag bei einem Kunden in <a href="http://de.wikipedia.org/wiki/D%C3%B6beln">Döbeln</a> (Sachsen).</p>
<p><a href="http://www.nautsch.net/wp-content/uploads/04062009-001.jpg"><img class="alignnone size-medium wp-image-336" title="Rathaus Döbeln" src="http://www.nautsch.net/wp-content/uploads/04062009-001-225x300.jpg" alt="Rathaus Döbeln" width="225" height="300" /></a></p>
<p>Thema des Workshops war ob einen nackten <a href="http://de.wikipedia.org/wiki/Swing_(Java)">Swing</a>-Client oder eine RCP-Applikation mit <a href="http://platform.netbeans.org/">Netbeans</a> bauen.  Schlussendlich haben mehr Argumente dafür gesprochen einen Swing-Client zu bauen.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nautsch.net/2009/06/09/swing-und-netbeans-rcp-in-dobeln/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>in, out, err bei externen Prozessen in Java</title>
		<link>http://www.nautsch.net/2009/05/06/in-out-err-bei-externen-prozessen-in-java/</link>
		<comments>http://www.nautsch.net/2009/05/06/in-out-err-bei-externen-prozessen-in-java/#comments</comments>
		<pubDate>Wed, 06 May 2009 09:36:46 +0000</pubDate>
		<dc:creator>oliver.nautsch</dc:creator>
				<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.nautsch.net/?p=309</guid>
		<description><![CDATA[Ich komme immer wieder durcheinander, wie die Streams eines externen Prozesses der aus Java gestartet wird (z.B. mit java.lang.ProcessBuilder) auf die Streams in Java abgebildet werden. Hier also mein Spickzettel:]]></description>
			<content:encoded><![CDATA[<p>Ich komme immer wieder durcheinander, wie die Streams eines externen Prozesses der aus Java gestartet wird (z.B. mit <a href="http://java.sun.com/javase/6/docs/api/java/lang/ProcessBuilder.html">java.lang.ProcessBuilder</a>) auf die Streams in Java abgebildet werden. Hier also mein Spickzettel:</p>
<p><img class="alignnone size-full wp-image-319" title="io-map-process-java1" src="http://www.nautsch.net/wp-content/uploads/io-map-process-java1.png" alt="io-map-process-java1" width="223" height="132" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nautsch.net/2009/05/06/in-out-err-bei-externen-prozessen-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dokumentation von Java Source Code</title>
		<link>http://www.nautsch.net/2009/03/03/dokumentation-von-java-source-code/</link>
		<comments>http://www.nautsch.net/2009/03/03/dokumentation-von-java-source-code/#comments</comments>
		<pubDate>Tue, 03 Mar 2009 20:56:59 +0000</pubDate>
		<dc:creator>oliver.nautsch</dc:creator>
				<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.nautsch.net/?p=263</guid>
		<description><![CDATA[Heute hatte ich eine Diskussion über die Art und Weise wie man in Java dokumentiert.  Was sind gute Kommentare? Was muss dokumentiert werden? Was kann man weglassen? Ich finde zu diesem Thema die Meinungen von Robert C. Martin gut, die er in seinem Buch Clean Code: A Handbook of Agile Software Craftmanship. Prentice Hall PTR. [...]]]></description>
			<content:encoded><![CDATA[<p>Heute hatte ich eine Diskussion über die Art und Weise wie man in Java dokumentiert.  Was sind gute Kommentare? Was muss dokumentiert werden? Was kann man weglassen?</p>
<p>Ich finde zu diesem Thema die Meinungen von <a href="http://en.wikipedia.org/wiki/Robert_C._Martin">Robert C. Martin</a> gut, die er in seinem Buch <a href="http://www.informit.com/store/product.aspx?isbn=0132350882"><em>Clean Code: A Handbook of Agile Software Craftmanship</em>. Prentice Hall PTR. 2008</a> unter dem Kapitel 4 &#8220;Comments&#8221; vertritt.</p>
<p>Ein paar Auszüge:</p>
<p>Seite 63:</p>
<blockquote><p>It is just plain silly to have a rule that says that every function must have a javadoc, or every variable must have a comment. Comments like this just clutter up the code, propagate lies, and lend to general confusion and disorganisation.</p></blockquote>
<p>Seite 64f.:</p>
<blockquote><p>And then there&#8217;s this paragon of redundancy:</p>
<pre>/**
 * Returns the day of the month.
 *
 * @return the day of the month.
 */
 public int getDayOfMonth() {
    return dayOfMonth;
 }</pre>
</blockquote>
<p>Seite 71:</p>
<blockquote><p>As useful as javadocs are for public API&#8217;s, they are anathema to code that is not intended for public consumption.</p></blockquote>
<p>Auch wenn ich hier Auszüge aus dem Kapitel &#8220;Bad Comments&#8221; bringe, so halte ich Kommentare und Dokumentation zum Job eines Softwareentwicklers. Öffentliche Methoden müssen eine nützliche Dokumentation haben (Bitte aber nicht wie in getDayOfMonth <img src='http://www.nautsch.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  ). Auch macht man sich oder seinen &#8220;Nachfolgern&#8221; oft das Leben wesentlich leichter seine Intention zu erklären, warum etwas genau so und nicht anders gemacht hat. Alles im Buch beschriebene möchte ich nicht hier wiedergeben. Einfach lesen.</p>
<p>Da aber Softwareentwicklung in den meisten Fällen im Team erfolgt, sollte man sich aber auf Regeln einigen und diese dann auch einhalten.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nautsch.net/2009/03/03/dokumentation-von-java-source-code/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Militaristen bei Spring Source?</title>
		<link>http://www.nautsch.net/2008/11/21/militaristen-bei-spring-source/</link>
		<comments>http://www.nautsch.net/2008/11/21/militaristen-bei-spring-source/#comments</comments>
		<pubDate>Fri, 21 Nov 2008 19:29:30 +0000</pubDate>
		<dc:creator>oliver.nautsch</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[leute]]></category>

		<guid isPermaLink="false">http://www.nautsch.net/?p=235</guid>
		<description><![CDATA[&#8220;Battling complexity?&#8221;, &#8220;Choose your weapon:&#8221; &#8220;Weapons for the War on &#8230;&#8221; &#8211; Diese Aussprüche habe ich gerade auf der Seite von Spring Source gefunden. Ich dachte bisher es ginge um Java (Spring Framework, und seit Kurzem auch Groovy und Grails). Jetzt habe ich aber das Gefühl in den Krieg ziehen zu müssen. Was soll der [...]]]></description>
			<content:encoded><![CDATA[<p>&#8220;Battling complexity?&#8221;, &#8220;Choose your weapon:&#8221; &#8220;Weapons for the War on &#8230;&#8221; &#8211; Diese Aussprüche habe ich gerade auf der Seite von <a href="http://www.springsource.com/">Spring Source</a> gefunden. Ich dachte bisher es ginge um Java (<a href="http://de.wikipedia.org/wiki/Spring_(Framework)">Spring Framework</a>, und seit <a href="http://www.springsource.com/g2one">Kurzem</a> auch Groovy und Grails). Jetzt habe ich aber das Gefühl in den Krieg ziehen zu müssen. Was soll der Quatsch? Die haben offensichtlich den falschen Mann fürs Marketing eingekauft. Zumindest für meinen Geschmack&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nautsch.net/2008/11/21/militaristen-bei-spring-source/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>statisch vs. new performance</title>
		<link>http://www.nautsch.net/2008/11/03/statisch-vs-new-performance/</link>
		<comments>http://www.nautsch.net/2008/11/03/statisch-vs-new-performance/#comments</comments>
		<pubDate>Mon, 03 Nov 2008 19:44:22 +0000</pubDate>
		<dc:creator>oliver.nautsch</dc:creator>
				<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.nautsch.net/?p=224</guid>
		<description><![CDATA[Heute hatten wir eine Diskussion darüber, ob auf einen Wert via einem statischen Klassenmember oder über einen Getter zugegriffen werden soll oder ob es sogar egal ist wenn man jedes Mal eine neue Instanz erzeugt. Jetzt hat es mich gejuckt, mal einfach ein kleines Beispiel zu machen. Mir ist klar, dass entscheidend ist, wie teuer [...]]]></description>
			<content:encoded><![CDATA[<p>Heute hatten wir eine Diskussion darüber, ob auf einen Wert via einem statischen Klassenmember oder über einen Getter zugegriffen werden soll oder ob es sogar egal ist wenn man jedes Mal eine neue Instanz erzeugt. Jetzt hat es mich gejuckt, mal einfach ein kleines Beispiel zu machen. Mir ist klar, dass entscheidend ist, wie teuer das erzeugen des Objektes ist. Aber hier sind einfach mal die Zahlen vom Beispiel um ein Gefühl zu bekommen:</p>
<blockquote><pre>
count: 10
static  msec: 0
get     msec: 0
new     msec: 0
count: 100
static  msec: 0
get     msec: 0
new     msec: 0
count: 1000
static  msec: 0
get     msec: 0
new     msec: 2
count: 10000
static  msec: 4
get     msec: 1
new     msec: 16
count: 100000
static  msec: 1
get     msec: 1
new     msec: 32
count: 1000000
static  msec: 0
get     msec: 0
new     msec: 224
count: 10000000
static  msec: 0
get     msec: 0
new     msec: 1848
count: 100000000
static  msec: 0
get     msec: 0
new     msec: 19029
</pre>
</blockquote>
<p>Und hier noch das Beispiel:</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('p224code18'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p22418"><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
63
64
65
66
67
68
69
</pre></td><td class="code" id="p224code18"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.HashMap</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.HashSet</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Map</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Set</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> Main <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> Person PERSON <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Person<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">long</span> timestamp<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">int</span> count <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">9</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</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%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;count: &quot;</span> <span style="color: #339933;">+</span> count<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            iterate<span style="color: #009900;">&#40;</span>count<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            count <span style="color: #339933;">*=</span> <span style="color: #cc66cc;">10</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;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> iterate<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> count<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        timestamp <span style="color: #339933;">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">currentTimeMillis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        iterateStatic<span style="color: #009900;">&#40;</span>count<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        out<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;static &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        timestamp <span style="color: #339933;">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">currentTimeMillis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        iterateGetter<span style="color: #009900;">&#40;</span>count<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        out<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;get    &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        timestamp <span style="color: #339933;">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">currentTimeMillis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        iterateNew<span style="color: #009900;">&#40;</span>count<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        out<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;new    &quot;</span><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;">private</span> <span style="color: #000000; font-weight: bold;">static</span> Person getPerson<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> PERSON<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> iterateStatic<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> count<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> count<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            Person person <span style="color: #339933;">=</span> PERSON<span style="color: #339933;">;</span>
            person.<span style="color: #006633;">blub</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> iterateNew<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> count<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> count<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            Person person <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Person<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            person.<span style="color: #006633;">blub</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> iterateGetter<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> count<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> count<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            Person person <span style="color: #339933;">=</span> getPerson<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            person.<span style="color: #006633;">blub</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> out<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> s<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>s <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; msec: &quot;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">currentTimeMillis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span>timestamp<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>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Person <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> Map<span style="color: #339933;">&lt;?</span>, <span style="color: #339933;">?&gt;</span> aMap <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HashMap<span style="color: #339933;">&lt;</span>String, Object<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> Set<span style="color: #339933;">&lt;?&gt;</span> aSet <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HashSet<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> Person<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">void</span> blub<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.nautsch.net/2008/11/03/statisch-vs-new-performance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
