<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Rich Internet Applications</title>
	<atom:link href="http://thomasholl.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://thomasholl.wordpress.com</link>
	<description>Flex, Code and Design</description>
	<lastBuildDate>Sat, 12 May 2007 11:21:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='thomasholl.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Rich Internet Applications</title>
		<link>http://thomasholl.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://thomasholl.wordpress.com/osd.xml" title="Rich Internet Applications" />
	<atom:link rel='hub' href='http://thomasholl.wordpress.com/?pushpress=hub'/>
		<item>
		<title>New location</title>
		<link>http://thomasholl.wordpress.com/2007/05/12/new-location/</link>
		<comments>http://thomasholl.wordpress.com/2007/05/12/new-location/#comments</comments>
		<pubDate>Sat, 12 May 2007 11:21:30 +0000</pubDate>
		<dc:creator>Thomas Holl</dc:creator>
				<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://thomasholl.wordpress.com/2007/05/12/new-location/</guid>
		<description><![CDATA[This Blog has moved to http://www.thomas-holl.com/wordpress. New articles will only be posted at the new location.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thomasholl.wordpress.com&amp;blog=1040612&amp;post=6&amp;subd=thomasholl&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This Blog has moved to <a href="http://www.thomas-holl.com/wordpress">http://www.thomas-holl.com/wordpress</a>. New articles will only be posted at the new location.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/thomasholl.wordpress.com/6/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/thomasholl.wordpress.com/6/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/thomasholl.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/thomasholl.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/thomasholl.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/thomasholl.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/thomasholl.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/thomasholl.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/thomasholl.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/thomasholl.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/thomasholl.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/thomasholl.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/thomasholl.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/thomasholl.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/thomasholl.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/thomasholl.wordpress.com/6/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thomasholl.wordpress.com&amp;blog=1040612&amp;post=6&amp;subd=thomasholl&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://thomasholl.wordpress.com/2007/05/12/new-location/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0a3208ec08f45804ef3084800cb320fd?s=96&#38;d=identicon" medium="image">
			<media:title type="html">thomasholl</media:title>
		</media:content>
	</item>
		<item>
		<title>The Humble MXML</title>
		<link>http://thomasholl.wordpress.com/2007/04/29/the-humble-mxml/</link>
		<comments>http://thomasholl.wordpress.com/2007/04/29/the-humble-mxml/#comments</comments>
		<pubDate>Sun, 29 Apr 2007 18:55:01 +0000</pubDate>
		<dc:creator>Thomas Holl</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[MXML]]></category>

		<guid isPermaLink="false">http://thomasholl.wordpress.com/2007/04/29/the-humble-mxml/</guid>
		<description><![CDATA[UPDATE: A new version of this article/blog While thinking about how to separate logic and user interface code on my current Flex project, I rerun into Michael Feathers great article about the &#8220;Humble Dialog Box&#8221;. I used this approach a couple of years before on a C++ project, was happy with it and I am [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thomasholl.wordpress.com&amp;blog=1040612&amp;post=5&amp;subd=thomasholl&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3><a href="http://www.thomas-holl.com/wordpress/the-humble-mxml/">UPDATE: A new version of this article/blog</a></h3>
<p>While thinking about how to separate logic and user interface code on my current Flex project, I rerun into <a href="http://www.michaelfeathers.com/">Michael Feathers</a> great article about the <a href="http://www.objectmentor.com/resources/articles/TheHumbleDialogBox.pdf">&#8220;Humble Dialog Box&#8221;</a>. I used this approach a couple of years before on a C++ project, was happy with it and I am now implementing it again. This article is about how to realize this separation in a Flex/MXML environment.</p>
<p>The basic idea of separating logic and ui code is propably as old as the first graphical user interfaces itself. Even older is the tendency to &#8220;just add the cool new feature&#8221; then &#8220;applying a fix here&#8221; and before your realize it, you&#8217;re stuck with the ui class handling everything. To cite from the article: <em>&#8220;It is easy to just override an event from a component and drop your interaction logic right there in the dialog box class.&#8221;</em></p>
<p>And the Flex/MXML ecosystem is no exception: As easy as Flex makes it to chum out MXML code that looks and work like a charm, it is also really easy to be led into a design which puts everything into the MXML file itself. The examples by Adobe are leading you exactly there. To be fair, their goal is coming to the point of showing off what the Flex Framework can do and not educating you about proper practices.</p>
<h2>Example</h2>
<p>I&#8217;ll describe the concepts with my component <em>ImageManager</em> as an example. First a screenshot of the component:</p>
<p><a href="http://thomasholl.files.wordpress.com/2007/04/imagemanager.png" title="ImageManager component"><img src="http://thomasholl.files.wordpress.com/2007/04/imagemanager.thumbnail.png?w=380" alt="ImageManager component" /></a></p>
<p><em>ImageManager</em> will provide the user a list of tags (the list on the left hand side) and (depending on which tag was chosen by the user) display a TileList of Images according to the tag. Search tags can also be entered manually by the user via the TextInput field. The real search is done on a <a href="http://www.rubyonrails.org">Ruby on Rails</a> server in the background (but that&#8217;s another topic). If a user clicks on a tag, the TextInput field will be updated with the search tags (could be words more than just the tag from the list).</p>
<h2>Concept and Realisation</h2>
<p>The Humble Dialog Box (in this case The Humble MXML) suggests to refactor the .MXML file into 3 entities which each have exactly one reason to exist (and only one reason to change):</p>
<ol>
<li><em>ImageManager.mxml:</em> The user interface itself, the MXML class. This class should contain mostly <code></code> and almost no code in the <code></code> tag</li>
<li><em>ImageManagerLogic.as:</em> The class handling the logic and only the logic. It communicates with the interface via the 3rd element, the interface</li>
<li><em>IImageManager.as:</em> The protocol to transfer information from the logic to the user interface</li>
</ol>
<p>Taking the logic out of the MXML and putting it into a separate class is pretty obvious. The <em>ImageManager.mxml</em> uses the <em>ImageManagerLogic</em> directly via a member-instance.</p>
<p>The interesting point in &#8220;The Humble MXML&#8221; is how to do the communication from the logic to the mxml. We don&#8217;t want the logic to depend on the user interface, so we obviously can&#8217;t reference the MXML file from the <em>ImageManagerLogic</em>. This is where the interface comes in: Put all callbacks from the logic into the <em>IImageManager</em> interface. In this example, when a user clicks the tags the TextInput has to be filled with the tags calculated by <em>ImageManagerLogic</em>. The <em>IImageManager</em> then looks like this:</p>
<pre>
<code>
interface IImageManager
{
	function set searchTags(t:String):void;
}
</code></pre>
<p>The <em>ImageManagerLogic</em> uses the <em>IImageManager</em> by calling <em>_view.searchTags = &#8230;</em>:</p>
<pre>
<code>
class ImageManagerLogic
{
	private var _view : IImageManager;

	public function set view(v:IImageManager):void
	{
		_view = v;
	}

	public function selectTag(index:int):void
	{
		_view.searchTags = tags[index].label;
		// then go on and trigger the search
	}

	// various private methods hidden

	public function searchForTags(tags:String):void
	{
		// do the search
	}
}
</code></pre>
<p>In the implementation of <em>ImageManager.mxml</em> the following happens:</p>
<ul>
<li>The <em>ImageManager.mxml</em> implements the <em>IImageManager</em> interface (<em>implements=&#8221;IImageManager&#8221;</em>) and tells the logic to use it (<em>logic.view = this</em>)</li>
<li>The implementation of the <em>IImageInterface</em> just puts the tags into the TextInput field</li>
<li>All event handlers just call the logic directly (e.g. <em>logic.searchForTags(&#8230;)</em>)</li>
</ul>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<p class="csharpcode">&nbsp;</p>
<pre><span class="lnum">   1:  </span><span class="kwrd">&lt;</span><span class="html">mx:Module</span> <span class="attr">implements</span><span class="kwrd">="IImageManager"</span> <span class="attr">initialize</span><span class="kwrd">="logic.view = this"</span><span class="kwrd">&gt;</span></pre>
<pre><span class="lnum">   2:  </span>    <span class="kwrd">&lt;</span><span class="html">mx:Script</span><span class="kwrd">&gt;</span></pre>
<pre><span class="lnum">   3:  </span>        <span class="kwrd">&lt;!</span>[CDATA[</pre>
<pre><span class="lnum">   4:  </span>            ImageManagerLogic logic;</pre>
<pre><span class="lnum">   5:  </span></pre>
<pre><span class="lnum">   6:  </span>            // implements IImageManager</pre>
<pre><span class="lnum">   7:  </span>            public function set searchTags(tags:String):void</pre>
<pre><span class="lnum">   8:  </span>            {</pre>
<pre><span class="lnum">   9:  </span>                inputSearchTags.text = tags;</pre>
<pre><span class="lnum">  10:  </span>            }</pre>
<pre><span class="lnum">  11:  </span>        ]]<span class="kwrd">&gt;</span></pre>
<pre><span class="lnum">  12:  </span>    <span class="kwrd">&lt;/</span><span class="html">mx:Script</span><span class="kwrd">&gt;</span></pre>
<pre><span class="lnum">  13:  </span></pre>
<pre><span class="lnum">  14:  </span>    <span class="kwrd">&lt;</span><span class="html">mx:HDividedBox</span> <span class="attr">width</span><span class="kwrd">="100%"</span> <span class="attr">height</span><span class="kwrd">="100%"</span><span class="kwrd">&gt;</span></pre>
<pre><span class="lnum">  15:  </span>        <span class="kwrd">&lt;</span><span class="html">mx:List</span> <span class="attr">width</span><span class="kwrd">="200"</span> <span class="attr">height</span><span class="kwrd">="100%"</span> <span class="attr">id</span><span class="kwrd">="list"</span></pre>
<pre><span class="lnum">  16:  </span>                <span class="attr">dataProvider</span><span class="kwrd">="{logic.tags}"</span></pre>
<pre><span class="lnum">  17:  </span>                <span class="attr">click</span><span class="kwrd">="logic.selectTag(list.selectedIndex)"</span> <span class="kwrd">/&gt;</span></pre>
<pre><span class="lnum">  18:  </span>        <span class="kwrd">&lt;</span><span class="html">mx:VBox</span> <span class="attr">width</span><span class="kwrd">="100%"</span> <span class="attr">height</span><span class="kwrd">="100%"</span><span class="kwrd">&gt;</span></pre>
<pre><span class="lnum">  19:  </span>            <span class="kwrd">&lt;</span><span class="html">mx:HBox</span><span class="kwrd">&gt;</span></pre>
<pre><span class="lnum">  20:  </span>                <span class="kwrd">&lt;</span><span class="html">mx:TextInput</span> <span class="attr">id</span><span class="kwrd">="inputSearchTags"</span></pre>
<pre><span class="lnum">  21:  </span>                        <span class="attr">enter</span><span class="kwrd">="logic.searchForTags(inputSearchTags.text)"</span><span class="kwrd">/&gt;</span></pre>
<pre><span class="lnum">  22:  </span>                <span class="kwrd">&lt;</span><span class="html">mx:Button</span> <span class="attr">label</span><span class="kwrd">="search"</span></pre>
<pre><span class="lnum">  23:  </span>                        <span class="attr">click</span><span class="kwrd">="logic.searchForTags(inputSearchTags.text)"</span><span class="kwrd">/&gt;</span></pre>
<pre><span class="lnum">  24:  </span>            <span class="kwrd">&lt;/</span><span class="html">mx:HBox</span><span class="kwrd">&gt;</span></pre>
<pre><span class="lnum">  25:  </span>            <span class="kwrd">&lt;</span><span class="html">mx:TileList</span> <span class="attr">dataProvider</span><span class="kwrd">="{logic.images}"</span> <span class="kwrd">/&gt;</span></pre>
<pre><span class="lnum">  26:  </span>        <span class="kwrd">&lt;/</span><span class="html">mx:VBox</span><span class="kwrd">&gt;</span></pre>
<pre><span class="lnum">  27:  </span>    <span class="kwrd">&lt;/</span><span class="html">mx:HDividedBox</span><span class="kwrd">&gt;</span></pre>
<pre><span class="lnum">  28:  </span><span class="kwrd">&lt;/</span><span class="html">mx:Module</span><span class="kwrd">&gt;</span></pre>
<h2>So, what do you get?</h2>
<ul>
<li><strong>Clear design:</strong> It is pretty obvious where to put stuff and where to look for it. If it is how something should look like (layout, formatting), it belongs into the .mxml file. If it processes data or calculates stuff, it belongs to the logic</li>
<li><strong>Reusability:</strong> It is easy to e.g. create an advanced ui/dialog by just wiring a new MXML class with the existing logic code. Or use the logic somewhere else, perhaps reusing it in another, more complex logic block</li>
<li><strong>Testability of the logic</strong> (by using a mock object for the view): Because the MXML just contains call to the logic if something happens, it is very probably the bug is in the logic &#8211; there you can have automated tests and need not to worry about the gui</li>
</ul>
<h2>Some things to consider</h2>
<ul>
<li>The only code allowed in the markup part of the .MXML file are calls to the logic layer. If you need complex calculations of input data (e.g. combining strings) for the logic layer this could be a sign that this functionality belongs into the logic. If it really doesn&#8217;t, put it in the <code></code> part</li>
<li>If there are no callbacks from the logic layer to the gui, you don&#8217;t need the interface <code>IImageManager</code></li>
</ul>
<h2>What does it cost?</h2>
<ul>
<li>You end up with 3 files instead of having just one. For small projects this may look like overkill, but even small projects can grow up real fast</li>
<li>Having to abstract the communication between the logic and the ui via an interface. For more complex patterns, this can be a real pain, but it is better to think about the protocol before instead of trying to seperate logic and ui at a later time when things got messed up</li>
</ul>
<h2>Opinions?</h2>
<ul>
<li>Do you consider this overkill?</li>
<li>Which unit testing frameworks do you use? Experiences?</li>
</ul>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/thomasholl.wordpress.com/5/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/thomasholl.wordpress.com/5/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/thomasholl.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/thomasholl.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/thomasholl.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/thomasholl.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/thomasholl.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/thomasholl.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/thomasholl.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/thomasholl.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/thomasholl.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/thomasholl.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/thomasholl.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/thomasholl.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/thomasholl.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/thomasholl.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thomasholl.wordpress.com&amp;blog=1040612&amp;post=5&amp;subd=thomasholl&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://thomasholl.wordpress.com/2007/04/29/the-humble-mxml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0a3208ec08f45804ef3084800cb320fd?s=96&#38;d=identicon" medium="image">
			<media:title type="html">thomasholl</media:title>
		</media:content>

		<media:content url="http://thomasholl.files.wordpress.com/2007/04/imagemanager.thumbnail.png" medium="image">
			<media:title type="html">ImageManager component</media:title>
		</media:content>
	</item>
	</channel>
</rss>
