<?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>javablog.ch&#187; Codestyle</title>
	<atom:link href="http://www.javablog.ch/category/codestyle/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.javablog.ch</link>
	<description>Keep on learning...</description>
	<lastBuildDate>Sun, 04 Dec 2011 17:15:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Effective Java: Builder-Pattern</title>
		<link>http://www.javablog.ch/2008/08/23/effective-java-builder-pattern/</link>
		<comments>http://www.javablog.ch/2008/08/23/effective-java-builder-pattern/#comments</comments>
		<pubDate>Sat, 23 Aug 2008 12:45:01 +0000</pubDate>
		<dc:creator>HeikoMaass</dc:creator>
				<category><![CDATA[Codestyle]]></category>

		<guid isPermaLink="false">http://www.javablog.ch/2008/08/23/effective-java-builder-pattern/</guid>
		<description><![CDATA[7 Jahre nach der ersten Auflage ist das Buch &#8220;Effective Java&#8221; von Joshua Bloch nun endlich in der zweiten Auflage erschienen. Der Klassiker wurde komplett runderneuert: Best-Practises für &#8216;neue&#8217; Sprachelemente wie Generics und Enums kamen hinzu, veraltete Kapitel (wie der Ersatz von C-Strukturen) wurden gestrichen. Neu ist auch das &#8220;Builder-Pattern&#8221;. Es kommt zum Einsatz, wenn [...]]]></description>
			<content:encoded><![CDATA[<p>7 Jahre nach der ersten Auflage ist das Buch &#8220;Effective Java&#8221; von Joshua Bloch nun endlich in der zweiten Auflage erschienen. Der Klassiker wurde komplett runderneuert: Best-Practises für &#8216;neue&#8217; Sprachelemente wie Generics und Enums kamen hinzu, veraltete Kapitel (wie der Ersatz von C-Strukturen) wurden gestrichen.</p>
<p>Neu ist auch das &#8220;Builder-Pattern&#8221;. Es kommt zum Einsatz, wenn ein Objekt viele optionale Variablen besitzt. Die bisherige, klassische Variante bei solchen Objekten ist das Schreiben von mehreren Konstruktoren (&#8216;telescoping constructor&#8217;), die über unterschiedliche Anzahl von Parametern verfügen. Allerdings sinkt die Lesbarkeit bei mehr als 6 Parametern gewaltig (vor allem wenn die Parameter vom gleichen Typ sind). </p>
<p>Das &#8220;Builder-Pattern&#8221; verzichtet auf die &#8216;telescoping constructors&#8217; und arbeitet stattdessen mit einer statischen inneren Klasse, die für das Erzeugen einer Instanz der äusseren Klasse zuständig ist. Der Konstruktor des Builder-Objekts enthält alle &#8220;Pflicht&#8221;-Variablen, die optionalen Variablen werden über (verkettbare) Methodenaufrufe hinzugefügt. Abschliessend wird die <code>build</code> Methode aufgerufen, die ein unveränderliches Objekt der äusseren Klasse erzeugt. Der Konstruktor der äusseren Klasse ist privat, d.h. nur ein Builder kann ein Objekt tatsächlich instanzieren:</p>
<p>Hier ein Beispiel:</p>
<div class="codeblock">
<div class="java" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #222222; font-weight: bold;">package</span> ch.<span style="color: #537799;font-weight: bold;">javablog</span>.<span style="color: #537799;font-weight: bold;">builderpattern</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #a1a100;">import java.math.BigDecimal;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #222222; font-weight: bold;">public</span> <span style="color: #222222; font-weight: bold;">class</span> Product <span style="color: #111111;">&#123;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// all fields are final: immutable object</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">private</span> <span style="color: #222222; font-weight: bold;">final</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: #415D77; ">String</span></a> id;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">private</span> <span style="color: #222222; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3ABigDecimal+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #415D77; ">BigDecimal</span></a> price;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">private</span> <span style="color: #222222; font-weight: bold;">final</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: #415D77; ">String</span></a> salesDescription;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">private</span> <span style="color: #222222; font-weight: bold;">final</span> Product baseProduct;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">private</span> <span style="color: #222222; font-weight: bold;">final</span> <span style="color: #222222; font-weight: bold;">boolean</span> approved;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">private</span> Product <span style="color: #111111;">&#40;</span>Builder builder<span style="color: #111111;">&#41;</span> <span style="color: #111111;">&#123;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// private Constructor can only be called from Builder</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">this</span>.<span style="color: #537799;font-weight: bold;">id</span> = builder.<span style="color: #537799;font-weight: bold;">id</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">this</span>.<span style="color: #537799;font-weight: bold;">price</span> = builder.<span style="color: #537799;font-weight: bold;">price</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">this</span>.<span style="color: #537799;font-weight: bold;">salesDescription</span> = builder.<span style="color: #537799;font-weight: bold;">salesDescription</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">this</span>.<span style="color: #537799;font-weight: bold;">baseProduct</span> = builder.<span style="color: #537799;font-weight: bold;">baseProduct</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">this</span>.<span style="color: #537799;font-weight: bold;">approved</span> = builder.<span style="color: #537799;font-weight: bold;">approved</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #111111;">&#125;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">public</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: #415D77; ">String</span></a> getId<span style="color: #111111;">&#40;</span><span style="color: #111111;">&#41;</span> <span style="color: #111111;">&#123;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">return</span> id;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #111111;">&#125;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3ABigDecimal+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #415D77; ">BigDecimal</span></a> getPrice<span style="color: #111111;">&#40;</span><span style="color: #111111;">&#41;</span> <span style="color: #111111;">&#123;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">return</span> price;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #111111;">&#125;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">public</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: #415D77; ">String</span></a> getSalesDescription<span style="color: #111111;">&#40;</span><span style="color: #111111;">&#41;</span> <span style="color: #111111;">&#123;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">return</span> salesDescription;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #111111;">&#125;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">public</span> Product getBaseProduct<span style="color: #111111;">&#40;</span><span style="color: #111111;">&#41;</span> <span style="color: #111111;">&#123;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">return</span> baseProduct;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #111111;">&#125;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">public</span> <span style="color: #222222; font-weight: bold;">boolean</span> isApproved<span style="color: #111111;">&#40;</span><span style="color: #111111;">&#41;</span> <span style="color: #111111;">&#123;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">return</span> approved;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #111111;">&#125;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">public</span> <span style="color: #222222; font-weight: bold;">static</span> <span style="color: #222222; font-weight: bold;">class</span> Builder <span style="color: #111111;">&#123;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// mandatory parameter</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">private</span> <span style="color: #222222; font-weight: bold;">final</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: #415D77; ">String</span></a> id;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">private</span> <span style="color: #222222; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3ABigDecimal+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #415D77; ">BigDecimal</span></a> price;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// optional</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">private</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: #415D77; ">String</span></a> salesDescription = <span style="color: #CF6F35;">&quot;&quot;</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">private</span> Product baseProduct &nbsp; &nbsp; = <span style="color: #222222; font-weight: bold;">null</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">private</span> <span style="color: #222222; font-weight: bold;">boolean</span> approved&nbsp; &nbsp; &nbsp; &nbsp; = <span style="color: #222222; font-weight: bold;">true</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">public</span> Builder<span style="color: #111111;">&#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: #415D77; ">String</span></a> id, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3ABigDecimal+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #415D77; ">BigDecimal</span></a> price<span style="color: #111111;">&#41;</span> <span style="color: #111111;">&#123;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">this</span>.<span style="color: #537799;font-weight: bold;">id</span> = id;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">this</span>.<span style="color: #537799;font-weight: bold;">price</span> = price;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #111111;">&#125;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">public</span> Builder salesDescription<span style="color: #111111;">&#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: #415D77; ">String</span></a> salesDescription<span style="color: #111111;">&#41;</span> <span style="color: #111111;">&#123;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">this</span>.<span style="color: #537799;font-weight: bold;">salesDescription</span> = salesDescription;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">return</span> <span style="color: #222222; font-weight: bold;">this</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #111111;">&#125;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">public</span> Builder baseProduct<span style="color: #111111;">&#40;</span>Product baseProduct<span style="color: #111111;">&#41;</span> <span style="color: #111111;">&#123;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">this</span>.<span style="color: #537799;font-weight: bold;">baseProduct</span> = baseProduct;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">return</span> <span style="color: #222222; font-weight: bold;">this</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #111111;">&#125;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">public</span> Builder approved<span style="color: #111111;">&#40;</span><span style="color: #222222; font-weight: bold;">boolean</span> approved<span style="color: #111111;">&#41;</span> <span style="color: #111111;">&#123;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">this</span>.<span style="color: #537799;font-weight: bold;">approved</span> = approved;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">return</span> <span style="color: #222222; font-weight: bold;">this</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #111111;">&#125;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">public</span> Product build<span style="color: #111111;">&#40;</span><span style="color: #111111;">&#41;</span> <span style="color: #111111;">&#123;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">return</span> <span style="color: #222222; font-weight: bold;">new</span> Product<span style="color: #111111;">&#40;</span><span style="color: #222222; font-weight: bold;">this</span><span style="color: #111111;">&#41;</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #111111;">&#125;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #111111;">&#125;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #111111;">&#125;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #222222; font-weight: bold;">public</span> <span style="color: #222222; font-weight: bold;">class</span> ProductClient <span style="color: #111111;">&#123;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">public</span> <span style="color: #222222; font-weight: bold;">static</span> <span style="color: #222222; font-weight: bold;">void</span> main<span style="color: #111111;">&#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: #415D77; ">String</span></a>... <span style="color: #537799;font-weight: bold;">args</span><span style="color: #111111;">&#41;</span> <span style="color: #111111;">&#123;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3ABigDecimal+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #415D77; ">BigDecimal</span></a> price = <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3ABigDecimal+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #415D77; ">BigDecimal</span></a>.<span style="color: #537799;font-weight: bold;">valueOf</span><span style="color: #111111;">&#40;</span><span style="color: #cc66cc;">36.5</span><span style="color: #111111;">&#41;</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Product.<span style="color: #537799;font-weight: bold;">Builder</span> builder = <span style="color: #222222; font-weight: bold;">new</span> Product.<span style="color: #537799;font-weight: bold;">Builder</span><span style="color: #111111;">&#40;</span><span style="color: #CF6F35;">&quot;050-0047&quot;</span>,price<span style="color: #111111;">&#41;</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// create Product using the builder</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Product p = builder</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .<span style="color: #537799;font-weight: bold;">salesDescription</span><span style="color: #111111;">&#40;</span><span style="color: #CF6F35;">&quot;great product&quot;</span><span style="color: #111111;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .<span style="color: #537799;font-weight: bold;">approved</span><span style="color: #111111;">&#40;</span><span style="color: #222222; font-weight: bold;">false</span><span style="color: #111111;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .<span style="color: #537799;font-weight: bold;">build</span><span style="color: #111111;">&#40;</span><span style="color: #111111;">&#41;</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #111111;">&#125;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #111111;">&#125;</span></div></li></ol></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.javablog.ch/2008/08/23/effective-java-builder-pattern/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>OVal &#8211; the object validation framework for Java 5 or later</title>
		<link>http://www.javablog.ch/2008/03/17/oval-the-object-validation-framework-for-java-5-or-later/</link>
		<comments>http://www.javablog.ch/2008/03/17/oval-the-object-validation-framework-for-java-5-or-later/#comments</comments>
		<pubDate>Mon, 17 Mar 2008 22:43:02 +0000</pubDate>
		<dc:creator>HeikoMaass</dc:creator>
				<category><![CDATA[Codestyle]]></category>
		<category><![CDATA[javabean]]></category>
		<category><![CDATA[javabeans]]></category>
		<category><![CDATA[oval]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://www.javablog.ch/2008/03/17/oval-the-object-validation-framework-for-java-5-or-later/</guid>
		<description><![CDATA[Ich muss gestehen, ich bin ein Fan von defensiver Programmierung, d.h. ich deklariere mögliche Inkonsistenzen von Objekten durch das Werfen von RuntimeExceptions (z.B. IllegalStateException oder IllegalArgumentException). Praktisch finde ich ebenfalls das Prinzip der Unveränderlichkeit. Einmal erzeugt, soll das Objekt nicht mehr verändert werden. Somit werden Inkonsistenzen (z.B. nicht gesetzte Attribute) bereits im Vorfeld vermieden. Allerdings [...]]]></description>
			<content:encoded><![CDATA[<p>Ich muss gestehen, ich bin ein Fan von defensiver Programmierung, d.h. ich deklariere mögliche Inkonsistenzen von Objekten durch das Werfen von RuntimeExceptions (z.B. <code>IllegalStateException</code> oder <code>IllegalArgumentException</code>). Praktisch finde ich ebenfalls das Prinzip der Unveränderlichkeit. Einmal erzeugt, soll das Objekt nicht mehr verändert werden. Somit werden Inkonsistenzen (z.B. nicht gesetzte Attribute) bereits im Vorfeld vermieden. </p>
<p>Allerdings verursacht diese Form der Absicherung unschönen Code-Overhead, da jeder Parameter manuell überprüft werden muss. Zudem stehen unveränderliche Objekte im Widerspruch mit der <a href="http://java.sun.com/javase/technologies/desktop/javabeans/index.jsp">JavaBean Spezifikation</a></p>
<p>Vor kurzem habe ich einen interessanten Lösungsansatz im <a href="http://oval.sourceforge.net/">OVal Framework</a> entdeckt. Hier werden die Properties und Methoden mit Annotations versehen und explizit oder implizit (via AspectJ) validiert. Beispiele gibts heute keine, stattdessen verweise ich auf die (gute) <a href="http://oval.sourceforge.net/#d0e7">Doku</a>. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.javablog.ch/2008/03/17/oval-the-object-validation-framework-for-java-5-or-later/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Buchtipp: Effektiv Java programmieren</title>
		<link>http://www.javablog.ch/2006/07/30/buchtipp-effektiv-java-programmieren/</link>
		<comments>http://www.javablog.ch/2006/07/30/buchtipp-effektiv-java-programmieren/#comments</comments>
		<pubDate>Sun, 30 Jul 2006 15:18:00 +0000</pubDate>
		<dc:creator>HeikoMaass</dc:creator>
				<category><![CDATA[Codestyle]]></category>

		<guid isPermaLink="false">http://www.javablog.ch/?p=21</guid>
		<description><![CDATA[&#8220;Effektiv Java programmieren&#8221; (ISBN 3-8273-1933-1) von Joshua Bloch gehört eindeutig zur Pflichtlektüre jedes professionellen Javaprogrammieres. In 57 kurz gehaltenen Kapiteln werden Regeln und Tipps für einen robusten und sauberen Programmierstil definiert. Als kleinen Appetitanreger fasse ich zwei seiner Regeln zusammen. Thema 9: Überschreiben Sie toString immer. Die toString Methode von java.lang.Object gibt standardmässig den Klassennamen [...]]]></description>
			<content:encoded><![CDATA[<p>&#8220;Effektiv Java programmieren&#8221; (ISBN 3-8273-1933-1) von Joshua Bloch gehört eindeutig zur Pflichtlektüre jedes professionellen Javaprogrammieres. In 57 kurz gehaltenen Kapiteln werden Regeln und Tipps für einen robusten und sauberen Programmierstil definiert. Als kleinen Appetitanreger fasse ich zwei seiner Regeln zusammen.</p>
<blockquote><p><strong>Thema 9: Überschreiben Sie toString immer.</strong></p></blockquote>
<p>Die <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html#hashCode()">toString </a>Methode von <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html">java.lang.Object</a> gibt standardmässig den Klassennamen und den Hashcode des Objects zurück. Für Debuggingzwecke ist diese Information nicht besonders aussagekräftig, von daher sollte jede Klasse diese Methode überschreiben und in ihr sämtliche relevanten Inhalte des Objekts zurückgeben.</p>
<p><strong>Beispiel</strong>: <code>toString </code>Methode aus <code>SquareTile </code>(Klasse zur Speicherung einer quadratischen Bildkachel in einer Kartenanwendung). Hier gibt die <code>toString</code> Methode die Koordinate der linken oberen Kante und die Breite zurück. Das ist beim Debugging (bzw. beim Logfile-Lesen) wesentlich hilfreicher als der Hashcode.</p>
<div class="codeblock">
<div class="java" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #222222; font-weight: bold;">public</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: #415D77; ">String</span></a> toString<span style="color: #111111;">&#40;</span><span style="color: #111111;">&#41;</span> <span style="color: #111111;">&#123;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #222222; font-weight: bold;">return</span> &nbsp;<span style="color: #CF6F35;">&quot;topLeftCoord: &quot;</span> + topLeftCoord.<span style="color: #537799;font-weight: bold;">toString</span><span style="color: #111111;">&#40;</span><span style="color: #111111;">&#41;</span> + <span style="color: #CF6F35;">'<span style="color: #000099; font-weight: bold;">\\</span>t'</span> +</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #CF6F35;">&quot;width == height: &quot;</span> + width;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #111111;">&#125;</span></div></li></ol></div>
</div>
<p><br/></p>
<blockquote><p><strong>Thema 13: Bevorzugen Sie Unveränderbarkeit</strong></p></blockquote>
<p>Unveränderliche Klassen erlauben lediglich bei der Konstruktion des Objekts das Setzen von Werten. Im Nachhinein können keine Werte mehr gesetzt werden (Es gibt also keine Setter-Methoden). Zudem sind alle Felder als <code>final </code>und <code>private </code>deklariert.</p>
<p><strong>Vorteil:</strong> Die Anzahl möglicher Zustände reduziert sich dramatisch, da das Objekt nach dem Konstruktor fertig initialisiert ist. Es gibt also keine unfertigen Objektstati, die man bei Methodenaufrufen überprüfen muss. Zudem sind solche Klassen automatisch Thread-sicher.<br />
Die Javabibliothek verwendet viele unveränderliche Klassen, z.B. <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html">java.lang.String</a> oder <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/math/BigInteger.html">java.math.BigInteger</a> .</p>
<p><strong>Nachteil:</strong> Für jeden Wert muss ein eigenes Objekt erzeugt werden. Bei vielen und grossen Objekten kann dies  recht kostspielig werden (bekanntester Effekt: Stringverkettung). Benötigt eine unveränderliche Klasse zudem viele Initialisierungsparameter, so leidet darunter die Lesbarkeit des Konstruktors, da hier alle Parameter übergeben werden müssen.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.javablog.ch/2006/07/30/buchtipp-effektiv-java-programmieren/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

