<?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>CertPal &#187; design</title>
	<atom:link href="http://www.certpal.com/blogs/tag/design/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.certpal.com/blogs</link>
	<description>Technology and certifications</description>
	<lastBuildDate>Mon, 18 Jul 2011 06:48:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Learning from design mistakes</title>
		<link>http://www.certpal.com/blogs/2010/11/learning-from-design-mistakes/</link>
		<comments>http://www.certpal.com/blogs/2010/11/learning-from-design-mistakes/#comments</comments>
		<pubDate>Wed, 03 Nov 2010 11:35:34 +0000</pubDate>
		<dc:creator>CertPal</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[learn]]></category>
		<category><![CDATA[mistakes]]></category>

		<guid isPermaLink="false">http://www.certpal.com/blogs/?p=916</guid>
		<description><![CDATA[A list of design mistakes that were made in the java API and how one can learn from them. The java SDK APIs make good use of patterns and practices, but there are places where it falls short.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F11%2Flearning-from-design-mistakes%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F11%2Flearning-from-design-mistakes%2F&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>While coming up with APIs or a framework, design forms a crucial part of the end result. While a solid design does indeed allow for flexible usage of an API, usability goes hand in hand with the design. What better way is there to create an API, than to learn from the mistakes and successes of other developers first ? Lets take a look at some examples in the java API where things could have been better&#8230;</p>
<h2>Stack and Properties:</h2>
<p>A java.util.Stack provides a standard Stack implementation in the java language. But did you know it extend a java.util.Vector ? Why is this wrong ? Because you can do this</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.design</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Stack</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Vector</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> StackTests
<span style="color: #009900;">&#123;</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><span style="color: #003399;">String</span>... <span style="color: #006633;">args</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">new</span> StackTests<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">go</span><span style="color: #009900;">&#40;</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;">public</span> <span style="color: #000066; font-weight: bold;">void</span> go<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        Vector<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> vector <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Stack<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>
        vector.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;first&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">Stack</span> <span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> stack <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Stack</span> <span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#41;</span> vector<span style="color: #339933;">;</span>
        <span style="color: #003399;">String</span> peek <span style="color: #339933;">=</span> stack.<span style="color: #006633;">peek</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>peek<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        stack.<span style="color: #006633;">push</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;next&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        stack.<span style="color: #006633;">push</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;item&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">String</span> remove <span style="color: #339933;">=</span> vector.<span style="color: #006633;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Removed: &quot;</span> <span style="color: #339933;">+</span> remove<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        peek <span style="color: #339933;">=</span> stack.<span style="color: #006633;">peek</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>peek<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
Output<span style="color: #339933;">:</span>
&nbsp;
first
Removed<span style="color: #339933;">:</span> item
next</pre></div></div>

<p>There are so many things that are going on there that are wrong.</p>
<ol>
<li>Vector is a slow DS. Its methods are synchronized and there is no way around this right now since this contract has been sealed. It cannot be changed without changing backward compatibility.</li>
<li>Vector has exposed its own methods to a stack. You should not be able to add() on to a stack.</li>
<li>Typecasting between Vector / Stack is plain weird.</li>
<li>Since the contract methods exposed by both classes operate on the same internal data structure, the outcome can often be confusing.</li>
</ol>
<p>This is something the API folks got wrong. This is not the only class that should have used composition over inheritance. The<a href="http://download.oracle.com/javase/6/docs/api/java/util/Properties.html" target="_blank"> java.util.Properties</a> class is another example. It extends from HashTable and now there is no way around that.</p>
<h2>Dummy variables:</h2>
<p>This one is probably not well known. A HashSet() has a default constructor which takes a boolean variable called dummy. It is never used. So why does it exist ? Its there because a LinkedHashSet (which extends the HashSet) uses this constructor to tell its super class that the backing data structure should be a LinkedHashMap. The advantage of doing this is that LinkedHashSet will have very little code to house into its implementation. </p>
<p><strong>From HashSet.java:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
* Constructs a new, empty linked hash set.  (This package private
* constructor is only used by LinkedHashSet.) The backing
* HashMap instance is a LinkedHashMap with the specified initial
* capacity and the specified load factor.
*
* @param      initialCapacity   the initial capacity of the hash map
* @param      loadFactor        the load factor of the hash map
* @param      dummy             ignored (distinguishes this
*             constructor from other int, float constructor.)
* @throws     IllegalArgumentException if the initial capacity is less
*             than zero, or if the load factor is nonpositive
*/</span>
<span style="color: #003399;">HashSet</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> initialCapacity, <span style="color: #000066; font-weight: bold;">float</span> loadFactor, <span style="color: #000066; font-weight: bold;">boolean</span> dummy<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    map <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> LinkedHashMap<span style="color: #009900;">&#40;</span>initialCapacity, loadFactor<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>It is not a great idea to write a separate constructor just because one sub class might need it. Secondly the javadoc explicitly mentions that only a LinkedHashSet uses this constructor. That message is a little confusing. Does that mean other subclasses are not meant to use this constructor ? Why does a subclass even need to know that ?</p>
<p>The side effect of this decision is not far reaching, as you may have already noted. Had the constructor been protected, the consequences would have been worse.</p>
<h2>Usability:</h2>
<p>The java community is pretty awesome. When a solution is too complicated, folks come out with a new framework / API to combat it. Take EJB for example. Versions 1 and 2 were pure horror. Version 3 is a little better. JEE6 has also learned a little from Spring.</p>
<p>This brings us to the java Date and its formatting APIs. Usability wise, many deprecated methods and confusing constructors make for a difficult time using the API. Which is why other solutions like <a href="http://joda-time.sourceforge.net/ " target="_blank">Joda time</a> and <a href="http://commons.apache.org/lang/api-release/org/apache/commons/lang/time/DateUtils.html" target="_blank">Apache commons date utils</a> pop up. The <a href="http://joda-time.sourceforge.net/ " target="_blank">&#8216;Why Joda Time?&#8217;</a> section helps explain what problem the API intends to solve where the JDK fell short.</p>
<p>In general, it will be hard to judge an API / framework without letting a few developers toy around with it first. The methods / constructors may well do what the contract defines them to do, but if it takes 100 steps against 10 to reach from point A to point B, guess which route a developer wants to take ?</p>
<hr/>
<p>In conclusion, these points are not about nitpicking the JDK / Java APIs in any manner. As long as developers learn from these mistakes, they can avoid them in their own code. The JDK is abundant with good usages of design patterns and some of its API are well thought out. Just avoid the bad design decisions whenever possible <img src='http://www.certpal.com/blogs/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p><script type="text/javascript">var dzone_url = 'http://www.certpal.com/blogs/2010/11/learning-from-design-mistakes/';</script><br />
<script type="text/javascript">var dzone_title = 'Learning from design mistakes';</script><br />
<script type="text/javascript">var dzone_blurb = 'A list of design mistakes that were made in the java API and how one can learn from them. The java SDK APIs make good use of patterns and practices, but there are places where it falls short.';</script><br />
<script type="text/javascript">var dzone_style = '2';</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script>
<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F11%2Flearning-from-design-mistakes%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F11%2Flearning-from-design-mistakes%2F&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
]]></content:encoded>
			<wfw:commentRss>http://www.certpal.com/blogs/2010/11/learning-from-design-mistakes/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Do you really need that design pattern ?</title>
		<link>http://www.certpal.com/blogs/2009/12/do-you-really-need-that-design-pattern/</link>
		<comments>http://www.certpal.com/blogs/2009/12/do-you-really-need-that-design-pattern/#comments</comments>
		<pubDate>Wed, 02 Dec 2009 15:25:16 +0000</pubDate>
		<dc:creator>CertPal</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[design]]></category>

		<guid isPermaLink="false">http://www.certpal.com/blogs/?p=481</guid>
		<description><![CDATA[Using design patterns where they do not belong can lead to over engineered code. Use patterns only when you really need to. Trivial code that is easy to maintain will always triumph over a complicated design pattern. In short, HelloWorld does not need a design pattern]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2009%2F12%2Fdo-you-really-need-that-design-pattern%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2009%2F12%2Fdo-you-really-need-that-design-pattern%2F&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>I chanced upon <a href="http://blogs.microsoft.co.il/blogs/gilf/archive/2009/11/22/applying-strategy-pattern-instead-of-using-switch-statements.aspx " target="_blank">a post </a>a while back about how a switch statement should be replaced with the strategy pattern. If you have not had a chance to go through it, please do. The post is not very long.  I found myself disagreeing very strongly with the author of the post and I was surprised to find that people thought this was a good idea.</p>
<p>The gist of the post was that using the Strategy pattern was better than using switch statements to determine which logic to execute. Here is why I think the idea used there was bad</p>
<ol>
<li>The introduction of the Strategy pattern, in the example, introduces three new classes. So for every case in a switch statement, we should go about replacing the corresponding code with a new class ? This could easily lead to an explosion in the number of classes.</li>
<li> Distributing logic across classes makes it harder for a developer to follow. When I traverse 2 / 3 links down a code path I might lose track of where I started.</li>
<li> Introducing a new case means I have to introduce one more class, remember to add that as a strategy and switch to that strategy correctly when the case is presented.</li>
<li>Introducing a new class to handle a &#8216;case&#8217; might not make sense. Classes are supposed to cohesively carry out a function. Introducing a new class for every function that a class is supposed to perform, dilutes the purpose of the class.</li>
<li>The code that was supposed to perform the switch case is simply done else where and called a strategy.</li>
</ol>
<p>Applying patterns where they do not belong, can be an anti pattern by itself. I can relate with what the author is trying to do. When I finished the &#8216;Head first design patterns&#8217; book I was racing to implement a pattern for everything that was around me. The book stopped me right there and warned &#8216;HelloWorld does not need a design pattern&#8217;. And they are absolutely right. For a design pattern to succeed, you need</p>
<ol>
<li>The right problem to apply the pattern.</li>
<li>Correct implementation of the pattern to solve the problem.</li>
<li>Knowledge and relevant documentation if necessary, to let the maintenance developer down the line know that this is how you used the pattern.</li>
</ol>
<p>Patterns are meant to solve common design problems but trying to use them everywhere can lead to overly engineered code that is hard to read and maintain. Use patterns only when they are necessary and help you solve the problem.
<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2009%2F12%2Fdo-you-really-need-that-design-pattern%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2009%2F12%2Fdo-you-really-need-that-design-pattern%2F&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
]]></content:encoded>
			<wfw:commentRss>http://www.certpal.com/blogs/2009/12/do-you-really-need-that-design-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Iterators &#8211; Fail fast Vs Fail safe</title>
		<link>http://www.certpal.com/blogs/2009/09/iterators-fail-fast-vs-fail-safe/</link>
		<comments>http://www.certpal.com/blogs/2009/09/iterators-fail-fast-vs-fail-safe/#comments</comments>
		<pubDate>Tue, 22 Sep 2009 15:57:46 +0000</pubDate>
		<dc:creator>CertPal</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[iterator]]></category>

		<guid isPermaLink="false">http://www.certpal.com/blogs/?p=311</guid>
		<description><![CDATA[An introduction into writing your own fail fast or fail safe iterators. Observing iterator behavior under various conditions can help a developer write a better one.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2009%2F09%2Fiterators-fail-fast-vs-fail-safe%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2009%2F09%2Fiterators-fail-fast-vs-fail-safe%2F&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Iterators can be designed so that they are <a href="http://en.wikipedia.org/wiki/Fail-fast" target="_blank">fail fast</a> or <a href="http://en.wikipedia.org/wiki/Fail-safe" target="_blank">fail safe</a>. Depending on the underlying implementation of the Iterator, a ConcurrentModificationException is thrown if the Collection is modified while Iterating over the data structure. It pays to understand how an Iterator will behave under both conditions. Lets try to implement fail fast Vs fail safe iterators of our own.</p>
<p>Our data structure for this example is pretty simple. It defines an interface that abstracts set and get operations on a structure. How the underlying classes handle invalid set operations or the size of the structure is implementation dependent</p>
<p><strong>A data structure interface:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> Data<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">extends</span> Iterable<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">int</span> size<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    T getElement<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> position<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">void</span> setElement<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> position, T t<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>An underlying implementation of such an Interface, could be say an array of Integers whose size is fixed. Invalid indexes on bounds are not allowed and the internal structure will not grow or shrink. An implementation is given below</p>
<p><strong>An array of integers implementing the interface:</strong></p>

<div class="wp_syntax"><div class="code"><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> ArrayOfIntegers <span style="color: #000000; font-weight: bold;">implements</span> Data<span style="color: #339933;">&lt;</span>Integer<span style="color: #339933;">&gt;</span>
<span style="color: #009900;">&#123;</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;">int</span> DEFAULT_SIZE <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1024</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> mods <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Integer</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> integers <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Integer</span><span style="color: #009900;">&#91;</span>DEFAULT_SIZE<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Integer</span> getElement<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> position<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        checkRange<span style="color: #009900;">&#40;</span>position<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> integers<span style="color: #009900;">&#91;</span>position<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setElement<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> position, <span style="color: #003399;">Integer</span> integer<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        checkRange<span style="color: #009900;">&#40;</span>position<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        mods<span style="color: #339933;">++;</span>
        integers<span style="color: #009900;">&#91;</span>position<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> integer<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> size<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> integers.<span style="color: #006633;">length</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> Iterator<span style="color: #339933;">&lt;</span>Integer<span style="color: #339933;">&gt;</span> iterator<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;">// return new FailFastIter();</span>
        <span style="color: #666666; font-style: italic;">// return new NoFailIter();</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>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> checkRange<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> position<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>position <span style="color: #339933;">&gt;</span> DEFAULT_SIZE <span style="color: #339933;">||</span> position <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0</span><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> <span style="color: #003399;">ArrayIndexOutOfBoundsException</span><span style="color: #009900;">&#40;</span>position<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: #666666; font-style: italic;">// Iterator implementations go here as a private class</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>If we wanted to Iterate over the ArrayOfIntegers structure, there are 2 ways to do it. Either ensure that the underlying data structure Integer[] integers is not modified while we iterate over ArrayOfIntegers, or make a copy of Integer[] integers so that any changes made to the internal structure will not affect the caller in any way. Let us look at 2 private Iterator classes that we can place into the ArrayOfIntegers class that will help us achieve both flavors of Iteration</p>
<p><strong>Fail fast:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">class</span> FailFastIter <span style="color: #000000; font-weight: bold;">implements</span> Iterator<span style="color: #339933;">&lt;</span>Integer<span style="color: #339933;">&gt;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">int</span> currentIndex <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">int</span> check <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">int</span> size <span style="color: #339933;">=</span> integers.<span style="color: #006633;">length</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> FailFastIter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        check <span style="color: #339933;">=</span> mods<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> hasNext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        checkForModification<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>currentIndex <span style="color: #339933;">&lt;</span> size<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;">true</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Integer</span> next<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        checkForModification<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">Integer</span> result <span style="color: #339933;">=</span> integers<span style="color: #009900;">&#91;</span>currentIndex<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        currentIndex<span style="color: #339933;">++;</span>
        <span style="color: #000000; font-weight: bold;">return</span> result<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> remove<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;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">UnsupportedOperationException</span><span style="color: #009900;">&#40;</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: #000066; font-weight: bold;">void</span> checkForModification<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;">if</span> <span style="color: #009900;">&#40;</span>check <span style="color: #339933;">!=</span> mods<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> <span style="color: #003399;">ConcurrentModificationException</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: #009900;">&#125;</span></pre></div></div>

<p>The fail fast Iterator in this example, refers to the internal data structure directly. Every modification to the internal structure is tracked using the &#8216;<strong>mods</strong>&#8216; variable. Our iterator stores this value when it was initially created using the &#8216;<strong>check</strong>&#8216; variable. Both variables are compared every time the hasNext() or next() methods are called. If they are unequal then it means that the underlying structure was changed. This is when the code throws a ConcurrentModificationException</p>
<p><strong>Fail safe:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">class</span> NoFailIter <span style="color: #000000; font-weight: bold;">implements</span> Iterator<span style="color: #339933;">&lt;</span>Integer<span style="color: #339933;">&gt;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">int</span> currentIndex <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
    <span style="color: #003399;">Integer</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> internal <span style="color: #339933;">=</span> <span style="color: #003399;">Arrays</span>.<span style="color: #006633;">copyOf</span><span style="color: #009900;">&#40;</span>integers, size<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: #000066; font-weight: bold;">int</span> internalSize <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> NoFailIter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        internalSize <span style="color: #339933;">=</span> internal.<span style="color: #006633;">length</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> hasNext<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;">if</span> <span style="color: #009900;">&#40;</span>currentIndex <span style="color: #339933;">&lt;</span> internalSize<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;">true</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Integer</span> next<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;">if</span> <span style="color: #009900;">&#40;</span>hasNext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #003399;">Integer</span> result <span style="color: #339933;">=</span> internal<span style="color: #009900;">&#91;</span>currentIndex<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            currentIndex<span style="color: #339933;">++;</span>
            <span style="color: #000000; font-weight: bold;">return</span> result<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">else</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> <span style="color: #003399;">NoSuchElementException</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>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> remove<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;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">UnsupportedOperationException</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></pre></div></div>

<p>The fail safe iterator makes a copy of the internal array data structure and uses it to iterate over the elements. This prevents any concurrent modification exceptions from being thrown if the underlying data structure changes. Of course, the overhead of copying the entire array is introduced. Both implementation can be tested using a program</p>
<p><strong>Iterator test for both iterators:</strong></p>

<div class="wp_syntax"><div class="code"><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> IterTest
<span style="color: #009900;">&#123;</span>
    <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><span style="color: #003399;">String</span>... <span style="color: #006633;">args</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">new</span> IterTest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">go</span><span style="color: #009900;">&#40;</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;">public</span> <span style="color: #000066; font-weight: bold;">void</span> go<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        Data<span style="color: #339933;">&lt;</span>Integer<span style="color: #339933;">&gt;</span> dataArray <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayOfIntegers<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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> iCounter <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> iCounter <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span> iCounter<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            dataArray.<span style="color: #006633;">setElement</span><span style="color: #009900;">&#40;</span>iCounter, iCounter<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        Iterator<span style="color: #339933;">&lt;</span>Integer<span style="color: #339933;">&gt;</span> iterator <span style="color: #339933;">=</span> dataArray.<span style="color: #006633;">iterator</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;">while</span> <span style="color: #009900;">&#40;</span>iterator.<span style="color: #006633;">hasNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>iterator.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            dataArray.<span style="color: #006633;">setElement</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">12</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: #009900;">&#125;</span></pre></div></div>

<p>By changing the Iterator implementation that the iterator() method returns, this test program will either throw a ConcurrentModificationException or iterate over all the elements without knowing what changed under the hood.</p>
<p>It makes sense to throw ConcurrentModificationException from an Iterator in certain cases. Under other scenarios you just don&#8217;t care if the Iterator will fail or survive an internal structure change. Taking a leaf out of the java Collection API, take a look at the Iterator behavior of an ArrayList Vs that of a CopyOnWriteArrayList. </p>
<p><strong>Iterator test for 2 iterators within the JDK API:</strong></p>

<div class="wp_syntax"><div class="code"><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> IterTest2
<span style="color: #009900;">&#123;</span>
    <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><span style="color: #003399;">String</span>... <span style="color: #006633;">args</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">new</span> IterTest2<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">go</span><span style="color: #009900;">&#40;</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;">public</span> <span style="color: #000066; font-weight: bold;">void</span> go<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        List<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> arList <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<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>
        List<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> copyList <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> CopyOnWriteArrayList<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>
        populate<span style="color: #009900;">&#40;</span>arList<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        populate<span style="color: #009900;">&#40;</span>copyList<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        iterate<span style="color: #009900;">&#40;</span>arList<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        iterate<span style="color: #009900;">&#40;</span>copyList<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: #000066; font-weight: bold;">void</span> populate<span style="color: #009900;">&#40;</span>List<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> list<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> iCounter <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> iCounter <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span> iCounter<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            list.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Integer</span><span style="color: #009900;">&#40;</span>iCounter<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toString</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>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> iterate<span style="color: #009900;">&#40;</span>List<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> list<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">try</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: #003399;">String</span> x <span style="color: #339933;">:</span> list<span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>x<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                list.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>x<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;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">RuntimeException</span> e<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            e.<span style="color: #006633;">printStackTrace</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: #009900;">&#125;</span></pre></div></div>

<p>The CopyOnWriteArrayList does not fail when the internal structure changes, but ArrayList does. This example better highlights the problem of fail fast Vs fail safe iterators. The next time your write a custom iterator for your classes, consider this decision.</p>
<p><strong>PS:</strong> The data structure defined here was just to illustrate the problem. You could certainly design this better by first providing an Abstract implementation that houses a private Iterator class, which will provide the default Iterator implementation for all subclasses. If the previous sentence sounds confusing, have a look at the <strong>Itr </strong>private class within the <strong>AbstractList </strong>class in the java source. The interface and implementation are much richer than the example provided here.</p>
<p><script type="text/javascript">var dzone_url = 'http://www.certpal.com/blogs/2009/09/iterators-fail-fast-vs-no-fail/';</script><br />
<script type="text/javascript">var dzone_title = 'Iterators - Fail fast Vs Fail safe';</script><br />
<script type="text/javascript">var dzone_blurb = 'An introduction into writing your own fail fast or fail safe iterators. Observing iterator behavior under various conditions can help a developer write a better one.';</script><br />
<script type="text/javascript">var dzone_style = '2';</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script>
<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2009%2F09%2Fiterators-fail-fast-vs-fail-safe%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2009%2F09%2Fiterators-fail-fast-vs-fail-safe%2F&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
]]></content:encoded>
			<wfw:commentRss>http://www.certpal.com/blogs/2009/09/iterators-fail-fast-vs-fail-safe/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

