<?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>ryan norris &#187; strategypattern</title>
	<atom:link href="http://www.ryannorris.com/tag/strategypattern/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ryannorris.com</link>
	<description>managing software teams and delivering great results</description>
	<lastBuildDate>Fri, 25 Jun 2010 13:44:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Common Java Idiom, Lousy GWT Bug</title>
		<link>http://www.ryannorris.com/2010/01/15/common-java-idiom-lousy-gwt-bug/</link>
		<comments>http://www.ryannorris.com/2010/01/15/common-java-idiom-lousy-gwt-bug/#comments</comments>
		<pubDate>Sat, 16 Jan 2010 04:49:29 +0000</pubDate>
		<dc:creator>Ryan Norris</dc:creator>
				<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[GWT]]></category>
		<category><![CDATA[Java Development]]></category>
		<category><![CDATA[Bugs]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[strategypattern]]></category>

		<guid isPermaLink="false">http://www.ryannorris.com/?p=145</guid>
		<description><![CDATA[I have to get around to shipping this one to the GWT committers, but this one bit me hard. Let&#8217;s say you have interface Driveable: public interface Driveable &#123; public void accelerate&#40;&#41;; &#160; public void brake&#40;&#41;; &#160; public void tuneRadio&#40;&#41;; &#125; Awesome. Now let&#8217;s say you have class AbstractDriveable: public abstract class AbstractDriveable implements Driveable [...]]]></description>
			<content:encoded><![CDATA[<p>I have to get around to shipping this one to the GWT committers, but this one bit me hard.</p>
<p><span id="more-145"></span>Let&#8217;s say you have interface Driveable:</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> Driveable <span style="color: #009900;">&#123;</span>
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> accelerate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> brake<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> tuneRadio<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Awesome. Now let&#8217;s say you have class AbstractDriveable:</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;">abstract</span> <span style="color: #000000; font-weight: bold;">class</span> AbstractDriveable <span style="color: #000000; font-weight: bold;">implements</span> Driveable <span style="color: #009900;">&#123;</span>
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> accelerate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #003399;">Window</span>.<span style="color: #006633;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Vroom vroom!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> brake<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #003399;">Window</span>.<span style="color: #006633;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Screeeeeech!&quot;</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>Totally cool.  And then you love your favorite FM station in ConcreteDriveable:</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> ConcreteDriveable <span style="color: #000000; font-weight: bold;">extends</span> AbstractDriveable <span style="color: #009900;">&#123;</span>
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> tuneRadio<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #003399;">Window</span>.<span style="color: #006633;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Rockin' the oldies!&quot;</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>Then we launch into development mode with whatever our application is, and&#8230;something explodes.</p>
<p>So we debug, and upon looking at the code that cleverly calls <code>tuneRadio</code> polymorphically &#8211; we notice that our debugger drops into a catch block for a <code>NoSuchMethodError</code>.</p>
<p>It appears that GWT seems to lose track of this common idiom &#8211; use an interface to define behavior, realize that interface on an abstract class to create default behaviors, and then strategize those behaviors in concrete implementations.</p>
<p>The workaround is simple: redeclare your unrealized interface method in the abstract class.  But this is a pretty nasty little bug.  The GWT guys know this, but it&#8217;s rather critical to GWT that it follow the practices of Java as best as possible.  Otherwise it&#8217;s YAL.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ryannorris.com/2010/01/15/common-java-idiom-lousy-gwt-bug/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
