<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Comparable vs. Comparator</title>
	<atom:link href="http://www.javablogging.com/comparable-vs-comparator/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.javablogging.com/comparable-vs-comparator/</link>
	<description>Tracking surprises, features and bugs</description>
	<lastBuildDate>Wed, 21 Jul 2010 14:19:17 -0500</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: miami fl lawyer</title>
		<link>http://www.javablogging.com/comparable-vs-comparator/comment-page-1/#comment-3271</link>
		<dc:creator>miami fl lawyer</dc:creator>
		<pubDate>Sun, 11 Jul 2010 01:46:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.javablogging.com/?p=522#comment-3271</guid>
		<description>Looking forward to finally finishing my research, great post!</description>
		<content:encoded><![CDATA[<p>Looking forward to finally finishing my research, great post!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: vibram five fingers kso shoes</title>
		<link>http://www.javablogging.com/comparable-vs-comparator/comment-page-1/#comment-3175</link>
		<dc:creator>vibram five fingers kso shoes</dc:creator>
		<pubDate>Sat, 03 Jul 2010 02:49:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.javablogging.com/?p=522#comment-3175</guid>
		<description>Women&#039;s  &lt;a href=&quot;http://www.vibramfivefingers.name&quot; rel=&quot;nofollow&quot;&gt;&lt;strong&gt;vibram five fingers kso shoes&lt;/strong&gt;&lt;/a&gt; Gray Pink Shoes can keep your feet in the freest condition,just as if your were barefooted. &lt;strong&gt;vibram five fingers kso shoes &lt;/strong&gt;is made of the best and proper materials,so you don&#039;t need to doubt of its comfort with so thin sole and upper.
Gray match with a dreamlike and romantic color,pink&lt;a href=&quot;http://www.vibramfivefingers.name&quot; rel=&quot;nofollow&quot;&gt;&lt;strong&gt; vibram five fingers kso shoes&lt;/strong&gt;&lt;/a&gt; is very consistent with the style of young girls.In this busy and tense times,people need relax without any fetter.</description>
		<content:encoded><![CDATA[<p>Women&#8217;s  <a href="http://www.vibramfivefingers.name" rel="nofollow"><strong>vibram five fingers kso shoes</strong></a> Gray Pink Shoes can keep your feet in the freest condition,just as if your were barefooted. <strong>vibram five fingers kso shoes </strong>is made of the best and proper materials,so you don&#8217;t need to doubt of its comfort with so thin sole and upper.<br />
Gray match with a dreamlike and romantic color,pink<a href="http://www.vibramfivefingers.name" rel="nofollow"><strong> vibram five fingers kso shoes</strong></a> is very consistent with the style of young girls.In this busy and tense times,people need relax without any fetter.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: WP Themes</title>
		<link>http://www.javablogging.com/comparable-vs-comparator/comment-page-1/#comment-1929</link>
		<dc:creator>WP Themes</dc:creator>
		<pubDate>Thu, 18 Mar 2010 03:23:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.javablogging.com/?p=522#comment-1929</guid>
		<description>Genial brief and this mail helped me alot in my college assignement. Thank you on your information.</description>
		<content:encoded><![CDATA[<p>Genial brief and this mail helped me alot in my college assignement. Thank you on your information.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pravin Jain</title>
		<link>http://www.javablogging.com/comparable-vs-comparator/comment-page-1/#comment-363</link>
		<dc:creator>Pravin Jain</dc:creator>
		<pubDate>Fri, 11 Sep 2009 12:01:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.javablogging.com/?p=522#comment-363</guid>
		<description>Comparable should be implemented to define natural ordering for Objects of a class, and every class may not have natural ordering.
Here for example if the SelectablePerson had an id field, then that could be used for natural ordering, since we would consider two SelectablePerson to be equal whenever their ids match. In all other cases, one should use a Comparator.</description>
		<content:encoded><![CDATA[<p>Comparable should be implemented to define natural ordering for Objects of a class, and every class may not have natural ordering.<br />
Here for example if the SelectablePerson had an id field, then that could be used for natural ordering, since we would consider two SelectablePerson to be equal whenever their ids match. In all other cases, one should use a Comparator.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jbisotti</title>
		<link>http://www.javablogging.com/comparable-vs-comparator/comment-page-1/#comment-312</link>
		<dc:creator>jbisotti</dc:creator>
		<pubDate>Tue, 01 Sep 2009 14:57:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.javablogging.com/?p=522#comment-312</guid>
		<description>&quot;The problem was not caused by ‘not reading Javadoc’ or faulty implementation of equals() but by a bad design decision of implementing Comparable instead of using a Comparator. You are also right that adding a field to SelectablePerson class could remove that bug, but it would only complicate the design and mask the real issue.&quot;

Really? IMHO, you are the one missing the main point. Regardless of if the design decision was a good one or not, the implementation is poor.  And it most definitely is not masking the real issue; it&#039;s exposing it.

Per your argument, you would blame the following on the Set interface, or the &quot;design decision&quot; to use a Set implementation:

final SelectablePerson p1 = new SelectablePerson( &quot;smith&quot; );

final SelectablePerson p2 = new SelectablePerson( &quot;smith&quot; );

final Set people = new HashSet();

people.add( p1 );
people.add( p2 );

// Fails because there&#039;s only one element in the Set
assertEquals( 2, people.size() );</description>
		<content:encoded><![CDATA[<p>&#8220;The problem was not caused by ‘not reading Javadoc’ or faulty implementation of equals() but by a bad design decision of implementing Comparable instead of using a Comparator. You are also right that adding a field to SelectablePerson class could remove that bug, but it would only complicate the design and mask the real issue.&#8221;</p>
<p>Really? IMHO, you are the one missing the main point. Regardless of if the design decision was a good one or not, the implementation is poor.  And it most definitely is not masking the real issue; it&#8217;s exposing it.</p>
<p>Per your argument, you would blame the following on the Set interface, or the &#8220;design decision&#8221; to use a Set implementation:</p>
<p>final SelectablePerson p1 = new SelectablePerson( &#8220;smith&#8221; );</p>
<p>final SelectablePerson p2 = new SelectablePerson( &#8220;smith&#8221; );</p>
<p>final Set people = new HashSet();</p>
<p>people.add( p1 );<br />
people.add( p2 );</p>
<p>// Fails because there&#8217;s only one element in the Set<br />
assertEquals( 2, people.size() );</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sakuraba</title>
		<link>http://www.javablogging.com/comparable-vs-comparator/comment-page-1/#comment-311</link>
		<dc:creator>Sakuraba</dc:creator>
		<pubDate>Tue, 01 Sep 2009 07:04:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.javablogging.com/?p=522#comment-311</guid>
		<description>Wouldn&#039;t all of this be sorted out if equals/hashcode were implemented correctly? Regardless of Comparable/Comparator?</description>
		<content:encoded><![CDATA[<p>Wouldn&#8217;t all of this be sorted out if equals/hashcode were implemented correctly? Regardless of Comparable/Comparator?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Helltime for August 31 &#171; I Built His Cage</title>
		<link>http://www.javablogging.com/comparable-vs-comparator/comment-page-1/#comment-309</link>
		<dc:creator>Helltime for August 31 &#171; I Built His Cage</dc:creator>
		<pubDate>Mon, 31 Aug 2009 21:05:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.javablogging.com/?p=522#comment-309</guid>
		<description>[...] chronicles an interesting tale on choosing between Comparable vs. Comparator. In short, the design decision to have an object implement Comparable led to problems later when [...]</description>
		<content:encoded><![CDATA[<p>[...] chronicles an interesting tale on choosing between Comparable vs. Comparator. In short, the design decision to have an object implement Comparable led to problems later when [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Benjamin Winterberg</title>
		<link>http://www.javablogging.com/comparable-vs-comparator/comment-page-1/#comment-308</link>
		<dc:creator>Benjamin Winterberg</dc:creator>
		<pubDate>Mon, 31 Aug 2009 19:19:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.javablogging.com/?p=522#comment-308</guid>
		<description>Interesting post, thanks for sharing.

For me the whole Observable / Observer is a bad implementation of the observer-pattern because you have to use inheritance.

For an imo much better realization of the observer pattern, check out the EventBus:

http://bwinterberg.blogspot.com/2009/05/eventbus-library.html</description>
		<content:encoded><![CDATA[<p>Interesting post, thanks for sharing.</p>
<p>For me the whole Observable / Observer is a bad implementation of the observer-pattern because you have to use inheritance.</p>
<p>For an imo much better realization of the observer pattern, check out the EventBus:</p>
<p><a href="http://bwinterberg.blogspot.com/2009/05/eventbus-library.html" rel="nofollow">http://bwinterberg.blogspot.com/2009/05/eventbus-library.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ppow</title>
		<link>http://www.javablogging.com/comparable-vs-comparator/comment-page-1/#comment-306</link>
		<dc:creator>ppow</dc:creator>
		<pubDate>Mon, 31 Aug 2009 17:28:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.javablogging.com/?p=522#comment-306</guid>
		<description>@Jeff: you are right about the direct causes of the error but I think you are missing the main issue here. The problem was not caused by &#039;not reading Javadoc&#039; or faulty implementation of equals() but by a bad design decision of implementing Comparable instead of using a Comparator.  You are also right that adding a field to SelectablePerson class could remove that bug, but it would only complicate the design and mask the real issue.</description>
		<content:encoded><![CDATA[<p>@Jeff: you are right about the direct causes of the error but I think you are missing the main issue here. The problem was not caused by &#8216;not reading Javadoc&#8217; or faulty implementation of equals() but by a bad design decision of implementing Comparable instead of using a Comparator.  You are also right that adding a field to SelectablePerson class could remove that bug, but it would only complicate the design and mask the real issue.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff</title>
		<link>http://www.javablogging.com/comparable-vs-comparator/comment-page-1/#comment-301</link>
		<dc:creator>Jeff</dc:creator>
		<pubDate>Mon, 31 Aug 2009 16:27:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.javablogging.com/?p=522#comment-301</guid>
		<description>There are a couple of issues at play here:

The first problem is that you did not read the javadoc for Observable&#039;s addObserver method.  It clearly states that it will only add an observer if an equal observer is not already in the set (note the term they used: &#039;set&#039; -- not &#039;list&#039;). 

The second problem is that your SelectablePerson object only uses name in its comparison.  The equals method says that all Smith&#039;s are equal.  Therefore, only one Smith will be added to an observable (or, for that matter, any Set).  If you want more than one Smith to be available in any Set, you must add other attributes to the object&#039;s &quot;business key&quot; or use some sort of surrogate ID (like the primary key in a database).  This won&#039;t help you sort by name... that&#039;s why Comparator was introduced.</description>
		<content:encoded><![CDATA[<p>There are a couple of issues at play here:</p>
<p>The first problem is that you did not read the javadoc for Observable&#8217;s addObserver method.  It clearly states that it will only add an observer if an equal observer is not already in the set (note the term they used: &#8217;set&#8217; &#8212; not &#8216;list&#8217;). </p>
<p>The second problem is that your SelectablePerson object only uses name in its comparison.  The equals method says that all Smith&#8217;s are equal.  Therefore, only one Smith will be added to an observable (or, for that matter, any Set).  If you want more than one Smith to be available in any Set, you must add other attributes to the object&#8217;s &#8220;business key&#8221; or use some sort of surrogate ID (like the primary key in a database).  This won&#8217;t help you sort by name&#8230; that&#8217;s why Comparator was introduced.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
