<?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/"
	>

<channel>
	<title>Asger Laursen</title>
	<atom:link href="http://asgerlaursen.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://asgerlaursen.com</link>
	<description>Flash Platform thoughts and stuff that goes around the RIA sphere</description>
	<pubDate>Mon, 18 May 2009 09:15:42 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Flex in my bank account</title>
		<link>http://asgerlaursen.com/2009/05/18/flex-in-my-bank-account/</link>
		<comments>http://asgerlaursen.com/2009/05/18/flex-in-my-bank-account/#comments</comments>
		<pubDate>Mon, 18 May 2009 09:02:38 +0000</pubDate>
		<dc:creator>Asger</dc:creator>
		
		<category><![CDATA[Flex]]></category>

		<category><![CDATA[Random Thoughts]]></category>

		<category><![CDATA[Banking]]></category>

		<category><![CDATA[RIA]]></category>

		<guid isPermaLink="false">http://asgerlaursen.com/?p=124</guid>
		<description><![CDATA[This morning I wanted to check out my financial wellbeing or the opposite at least. So I logged into my home-banking account, and selected the overview. This morning things was different, and not related to my actual monetary situation, but due to the nice animating charting component which folded out and showed me a graphical [...]]]></description>
			<content:encoded><![CDATA[<p>This morning I wanted to check out my financial wellbeing or the opposite at least. So I logged into my home-banking account, and selected the overview. This morning things was different, and not related to my actual monetary situation, but due to the nice animating charting component which folded out and showed me a graphical overview.</p>
<p><img alt="" src="http://asgerlaursen.com/wp-content/uploads/2009/18_05_2009/chart1.png" title="Chart one" class="alignnone" width="658" height="291" /></p>
<p>I was pretty amazed and thrilled for various reasons, first of, the use of the Flash Platform in a banking application is always a great manifest of what is going on; the Flash Platform has made it&#8217;s transition from an animation - banner add - micro site - video player  -only platform to a state where it is also an enterprise platform. This statement; &#8220;Flash Platform is an enterprise platform&#8221; is not new at all, I know I for one have preached it to clients over and over the past couple of years, but still, seeing Flash Player used in a home banking app, was a great testimony. As we all know (especially in these times marked in history as &#8220;the financial crises&#8221;) banks are watching their money with every means there is. So Flash running inside my home banking is a sign of belief and acceptance of the Flash Platform as secure, reliable and suited for enterprise solutions.</p>
<p><img alt="" src="http://asgerlaursen.com/wp-content/uploads/2009/18_05_2009/chart2.png" title="Chart 2" class="alignnone" width="661" height="284" /></p>
<p>Another reason for my happiness as related to a high level view on the RIA sphere I live and work in. I&#8217;ve only had a few different banks in my life, so I can&#8217;t answer for all of them, but on thing which have been similar to all of them, has been the definition of &#8220;overview&#8221; when wanting to see your account. The visual presentation of this has always been a refresh of the page followed by a list of dated entries; deposits and withdrawals, and that was it. You could then scroll up and down, and select a new period, and your page would refresh and show a new list, with entries within the new set of calendar boundaries. To see your accounts evolution visually in a graphical chart, first of gives a much nicer overview, you can easily see what&#8217;s going on from month to month, or day to day. Being able to easily see the curve of your monetary situation or a comparison  between deposits and withdrawals is of great value. When setting the granularity of the graph or the time span in general, no page refresh was needed, the graph just transitioned to its new state, reflecting the data model behind. This was *really* great! A field (at least in Denmark it is) so conservative as the banking sector, implementing a Richness in their Internet Applications is a good step forward and manifest of RIA being a valid use case for better end user experience.</p>
<p>In summery onne might rephrase this to; &#8220;One small step for Rich Internet Applications, one giant leap for Home Banking Applications&#8221; <img src='http://asgerlaursen.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Cheers</p>
<p>Asger</p>
]]></content:encoded>
			<wfw:commentRss>http://asgerlaursen.com/2009/05/18/flex-in-my-bank-account/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Flash Builder Browser - the world as it should be</title>
		<link>http://asgerlaursen.com/2009/05/16/flash-builder-browser-the-world-as-it-should-be/</link>
		<comments>http://asgerlaursen.com/2009/05/16/flash-builder-browser-the-world-as-it-should-be/#comments</comments>
		<pubDate>Sat, 16 May 2009 12:25:10 +0000</pubDate>
		<dc:creator>Asger</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[Flash Builder]]></category>

		<category><![CDATA[Funny]]></category>

		<category><![CDATA[Joke]]></category>

		<category><![CDATA[Renaming]]></category>

		<guid isPermaLink="false">http://asgerlaursen.com/?p=119</guid>
		<description><![CDATA[What happend - the motivation
As you might now Flex Builder just got a renaming to the much more coherent Flash Builder.
On of the arguments in favor of the renaming is of cause to lower the misunderstandings between what is Flash, what is Flex, and what is Flex builder.
The Problem
New people in the Flash Platform world [...]]]></description>
			<content:encoded><![CDATA[<p><strong>What happend - the motivation</strong><br />
As you might now Flex Builder just got a renaming to the much more coherent Flash Builder.<br />
On of the arguments in favor of the renaming is of cause to lower the misunderstandings between what is Flash, what is Flex, and what is Flex builder.</p>
<p><strong>The Problem</strong><br />
New people in the Flash Platform world is often confused about what is what, when talking about Flex and the Builder tool. This renaming will of cause help solve this in the future. But what about the past? What about all these articles, pages, tutorials etc online which still interchangeably uses Flex and Flex Builder without making a differ?</p>
<p><strong>The Solution</strong><br />
Enter Flash Builder Browser. - your way to see the future, while reading yesterdays news!<br />
Flash Builder Browser is an easy to use browser which alters the content you read, so you wont get confused!<br />
Start getting into the Flash Platform loop with the Flash Builder Browser!</p>
<p><strong>Examples and code</strong><br />
Her is how the world looked yesterday:<br />
<img alt="" src="http://asgerlaursen.com/wp-content/uploads/2009/16_05_2009/yesterday.png" title="Yesterday" class="alignnone" width="670" height="592" /></p>
<p>And here is how the world looks trough Flash Builder Browser:<br />
<img alt="" src="http://asgerlaursen.com/wp-content/uploads/2009/16_05_2009/tomorrow.png" title="Tomorrow" class="alignnone" width="706" height="598" /></p>
<p>Get your own copy of Flash Builder Browser and start seeing the world as it is!<br />
<a href="http://asgerlaursen.com/wp-content/uploads/2009/16_05_2009/FlashBuilderBrowser.air" >Download AIR application here</a></p>
<p><strong>Get Involved</strong><br />
Here is the source code, giving you the option to start creating, modifying and improving the Flash Builder Browser.</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p119code3'); return false;">View Code</a> MXML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p1193"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code" id="p119code3"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:WindowedApplication</span> width=<span style="color: #ff0000;">&quot;900&quot;</span> height=<span style="color: #ff0000;">&quot;900&quot;</span> xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/halo&quot;</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:creationComplete</span><span style="color: #7400FF;">&gt;</span></span>
		address.text = &quot;http://www.adobe.com/products/flex/&quot;
		browser.location = address.text;
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:creationComplete</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:VGroup</span> verticalCenter=<span style="color: #ff0000;">&quot;0&quot;</span> horizontalCenter=<span style="color: #ff0000;">&quot;0&quot;</span> height=<span style="color: #ff0000;">&quot;90%&quot;</span> width=<span style="color: #ff0000;">&quot;90%&quot;</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:HGroup</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> height=<span style="color: #ff0000;">&quot;30&quot;</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:TextInput</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> id=<span style="color: #ff0000;">&quot;address&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Button</span> label=<span style="color: #ff0000;">&quot;Go&quot;</span> id=<span style="color: #ff0000;">&quot;goBtn&quot;</span><span style="color: #7400FF;">&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:click</span><span style="color: #7400FF;">&gt;</span></span>
			browser.location = address.text;
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:click</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Button</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:HGroup</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:HTML</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> height=<span style="color: #ff0000;">&quot;100%&quot;</span> id=<span style="color: #ff0000;">&quot;browser&quot;</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:htmlRender</span><span style="color: #7400FF;">&gt;</span></span>
				var flashBuilderPattern:RegExp = /(flex)(®)? +(builder|plugin|plug in)/ig
				if(browser.htmlLoader.window.document.body)
					browser.htmlLoader.window.document.body.innerHTML = String(browser.htmlLoader.window.document.body.innerHTML).replace(flashBuilderPattern,&quot;Flash$2  $3&quot;);
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:htmlRender</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:HTML</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:VGroup</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:WindowedApplication</span><span style="color: #7400FF;">&gt;</span></span></pre></td></tr></table></div>

<p>Happy Coding</p>
<p><strong>UPDATE</strong>:<br />
Actually realized that I&#8217;d put the regexp code in the htmlRender event, which is not the best place, as it gets called over and over, and could make the browser malfunctioning.<br />
So, even though this post is nothing more than a practical joke, I updated the source, and added some extra things to the usability! (note to self; find a hobby).</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p119code4'); return false;">View Code</a> MXML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p1194"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
</pre></td><td class="code" id="p119code4"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:WindowedApplication</span> width=<span style="color: #ff0000;">&quot;900&quot;</span> height=<span style="color: #ff0000;">&quot;900&quot;</span> xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/halo&quot;</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Script</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;">&lt;!<span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span></span>
<span style="color: #000000;">			import mx.managers.CursorManager;</span>
&nbsp;
<span style="color: #000000;">			private function goToUrl<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:void</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">				browser.location = <span style="color: #ff0000;">&quot;http://&quot;</span>+address.text;</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#125;</span></span>
<span style="color: #000000;">		<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Script</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:states</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:State</span> name=<span style="color: #ff0000;">&quot;idle&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:State</span> name=<span style="color: #ff0000;">&quot;loading&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:states</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:creationComplete</span><span style="color: #7400FF;">&gt;</span></span>
		address.text = &quot;www.adobe.com/products/flex/&quot;
		goToUrl();
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:creationComplete</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:VGroup</span> verticalCenter=<span style="color: #ff0000;">&quot;0&quot;</span> horizontalCenter=<span style="color: #ff0000;">&quot;0&quot;</span> height=<span style="color: #ff0000;">&quot;90%&quot;</span> width=<span style="color: #ff0000;">&quot;90%&quot;</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:SimpleText</span> text=<span style="color: #ff0000;">&quot;Page Loaded&quot;</span><span style="color: #7400FF;">&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:text</span>.loading<span style="color: #7400FF;">&gt;</span></span>Loading page...<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:text</span>.loading<span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:SimpleText</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:HGroup</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> height=<span style="color: #ff0000;">&quot;30&quot;</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:SimpleText</span> text=<span style="color: #ff0000;">&quot;http://&quot;</span> fontSize=<span style="color: #ff0000;">&quot;16&quot;</span> fontWeight=<span style="color: #ff0000;">&quot;bold&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:TextInput</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> id=<span style="color: #ff0000;">&quot;address&quot;</span> text=<span style="color: #ff0000;">&quot;{browser.location.replace('http://','')}&quot;</span> enter=<span style="color: #ff0000;">&quot;goToUrl()&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Button</span> label=<span style="color: #ff0000;">&quot;Go&quot;</span> id=<span style="color: #ff0000;">&quot;goBtn&quot;</span><span style="color: #7400FF;">&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:click</span><span style="color: #7400FF;">&gt;</span></span>
				goToUrl();
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:click</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Button</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:HGroup</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:HTML</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> height=<span style="color: #ff0000;">&quot;100%&quot;</span> id=<span style="color: #ff0000;">&quot;browser&quot;</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:complete</span><span style="color: #7400FF;">&gt;</span></span>
				if(browser.htmlLoader.window.document.body)
				{
					var flashBuilderPattern:RegExp = /(flex)(®)? +(builder|plugin|plug in)/ig
					trace(&quot;laver vi søgning???&quot;);
					browser.htmlLoader.window.document.body.innerHTML = String(browser.htmlLoader.window.document.body.innerHTML).replace(flashBuilderPattern,&quot;Flash$2  $3&quot;);
				}
				currentState = &quot;idle&quot;;
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:complete</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:locationChange</span><span style="color: #7400FF;">&gt;</span></span>
			currentState = &quot;loading&quot;;
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:locationChange</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:HTML</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:VGroup</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:WindowedApplication</span><span style="color: #7400FF;">&gt;</span></span></pre></td></tr></table></div>

<p>And of cause the AIR application has been updated as well.</p>
<p>And this I hope is the end of this post *ever* <img src='http://asgerlaursen.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' /> </p>
<p><a href="http://asgerlaursen.com/wp-content/uploads/2009/16_05_2009/FlashBuilderBrowser.air" >Download AIR application here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://asgerlaursen.com/2009/05/16/flash-builder-browser-the-world-as-it-should-be/feed/</wfw:commentRss>
		</item>
		<item>
		<title>ActionScript, RIA and DSL part 1 ½</title>
		<link>http://asgerlaursen.com/2009/01/28/actionscript-ria-and-dsl-part-1-%c2%bd/</link>
		<comments>http://asgerlaursen.com/2009/01/28/actionscript-ria-and-dsl-part-1-%c2%bd/#comments</comments>
		<pubDate>Wed, 28 Jan 2009 22:58:41 +0000</pubDate>
		<dc:creator>Asger</dc:creator>
		
		<category><![CDATA[ActionScript]]></category>

		<category><![CDATA[Business Domain]]></category>

		<category><![CDATA[DSL]]></category>

		<category><![CDATA[Language Constructs]]></category>

		<guid isPermaLink="false">http://asgerlaursen.com/?p=108</guid>
		<description><![CDATA[Introduction
This post is actually a somewhat intermezzo, and wasn&#8217;t in my plans. But in my writings of part 1, I happed to post a non working example of a DSL.
I didn&#8217;t see the fault my self, but Dmitry Miterev was so kind to point me attention to it. - so I guess this blog post [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Introduction</strong><br />
This post is actually a somewhat intermezzo, and wasn&#8217;t in my plans. But in my writings of <a href="http://asgerlaursen.com/2008/12/14/ria-and-dsl-part-1/#comments" >part 1</a>, I happed to post a non working example of a DSL.<br />
I didn&#8217;t see the fault my self, but <a href="http://asgerlaursen.com/2008/12/14/ria-and-dsl-part-1/#comments" >Dmitry Miterev</a> was so kind to point me attention to it. - so I guess this blog post is dedicated to him <img src='http://asgerlaursen.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>Background</strong><br />
When I started looking into the opportunities for writing a DSL with AS3, I did a lot of testing and tweaking to see how the language features could help enable me to write a more fluent DSL. Especially the getter / setter features was of great interest as these in their nature removed a lot of noise from the language.</p>
<p><strong>The bad example</strong><br />
In my first post, I pointed out, that to get the Coffee example to work, you could just use a setter returning a reference to the object, containing the property. This can be done, but to things are wrong in the example:</p>
<p>1) It is not possible to type the return type if you want to return the instance:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p108code10'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p10810"><td class="code" id="p108code10"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyClass
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">//Not legal setter</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> myProperty<span style="color: #66cc66;">&#40;</span>value:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:MyClass
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #0066CC;">this</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">//Legal setter</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> myOtherProperty<span style="color: #66cc66;">&#40;</span>value:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #66cc66;">*</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #0066CC;">this</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>So as you can see, you can mark the setter as &#8221; * &#8221; for an arbitrary value.</p>
<p>2)It is not the feature we are looking fore to solve the design we want in the Coffee example; we need the getter / setter to make the Coffee example work, but the above feature, which for sure can come in handy in DSL cases, is not the one used to create the example.</p>
<p><strong>So what went wrong </strong><br />
I guess writing this post, and playing around with DSL&#8217;s in AS 3 for a longer period of time, made me grab, at least what I thought was the, &#8220;last working Coffee example&#8221; and use that. I guess the lesson is learned; compile and test code before blogging it.</p>
<p><strong>The right example</strong><br />
So without further ado I&#8217;ll jump into the Coffee example I actually got to work, when playing around. One thing different though is that the working implementation do not allow for &#8220;direct value&#8221; like the number defining the temperature of the coffee.<br />
Having reviewed the working example again, I think the best description of the &#8220;pattern&#8221; if a such can be derived, would be &#8220;Reverse Chain Method&#8221;, meaning that the last object in the chain, is created first and collects the values from the previous objects in the chain.<br />
But before I turn this blog into a drag like the first part, lets look at the code. - it will also put my definition into context.</p>
<p><strong>The structure</strong><br />
The idea of this way of getting the look and feel of the DSL is to replace the actual class getting instantiated by a subclass (or subclass of subclass) which has the same properties as the base class. So to identify the players in our exampel:<br />
The Coffee class, the class (we think) we manipulate<br />
The Coffee Value, the class representing a value we want to assign to the coffee, say a temperature, a size etc. The CoffeeValue class is a helper class with the logic to perform the revers chaining.<br />
The Concrete value classes, these classes are the concrete implementations of values, so the actual Temperature, Size or Consumption class. These are all sub classes to CoffeeValue, which it self is a subclass to Coffee. To mark the and use the polymorphisms we have a set of marker interfaces, one for CoffeeValue, Template, Size etc.<br />
The complete diagram looks like this:</p>
<p><img src="http://asgerlaursen.com/wp-content/uploads/2009/28_01_2009/28-01-2009%2022-57-46.png" alt="Reverse Method Chain Diagram" /> </p>
<p>So to start looking at the language we want to build, we have the Coffee example below. As you can see, in this example the temperature now refers to a static property, instead of a value.</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p108code11'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p10811"><td class="code" id="p108code11"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> makeCoffee<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> latte:Coffee = <span style="color: #000000; font-weight: bold;">new</span> Coffee<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
	.<span style="color: #006600;">water</span> = ConcreteWater.<span style="color: #006600;">NO_WATER</span>
	.<span style="color: #0066CC;">type</span> = ConcreteCoffeeType.<span style="color: #006600;">TAZO_CHAI_TEA_LATTE</span>
	.<span style="color: #006600;">fat</span> = ConcreteFatContent.<span style="color: #006600;">NON_FAT</span>
	.<span style="color: #0066CC;">size</span> = ConcreteCoffeeSize.<span style="color: #006600;">GRANDE</span>
	.<span style="color: #006600;">where</span> = ConcreteConsumption.<span style="color: #006600;">FOR_HERE</span>
	.<span style="color: #006600;">temperature</span> = ConcreteTemperature.<span style="color: #006600;">HOT</span> 	
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p><strong>Coffe Time</strong><br />
So what happens inside the various classes. I&#8217;ll start be looking at the Coffee class, to see how the internals in structured.</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p108code12'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p10812"><td class="code" id="p108code12"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Coffee
	<span style="color: #66cc66;">&#123;</span>
		protected <span style="color: #000000; font-weight: bold;">var</span> _size:CoffeeSize;
		protected <span style="color: #000000; font-weight: bold;">var</span> _where:Consumption;
		protected <span style="color: #000000; font-weight: bold;">var</span> _fat:FatContent;
		protected <span style="color: #000000; font-weight: bold;">var</span> _water:Water;
		protected <span style="color: #000000; font-weight: bold;">var</span> _temperature:Temperature;
		protected <span style="color: #000000; font-weight: bold;">var</span> _type:CoffeeType;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Coffee<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
&nbsp;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> <span style="color: #0066CC;">size</span><span style="color: #66cc66;">&#40;</span>value:<span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			_size = value;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> <span style="color: #0066CC;">size</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:CoffeeSize
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> _size;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> where<span style="color: #66cc66;">&#40;</span>value:<span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			_where = value;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> where<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:Consumption
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> _where;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> fat<span style="color: #66cc66;">&#40;</span>value:<span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			_fat = value;
		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> fat<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:FatContent
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> _fat;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> water<span style="color: #66cc66;">&#40;</span>value:<span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			_water = value;
		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> water<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:Water
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> _water;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> temperature<span style="color: #66cc66;">&#40;</span>value:<span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			_temperature = value;
		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> temperature<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:Temperature
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> _temperature;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> <span style="color: #0066CC;">type</span><span style="color: #66cc66;">&#40;</span>value:<span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			_type = value;
		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> <span style="color: #0066CC;">type</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:CoffeeType
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> _type;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>What is worth noticing in Coffee is that our setters expect an arbitrary data type; this is needed for us to make the chain move backwards, as the same object is being send in to each setter trough out the chain.<br />
Besides the setters the properties is made protected as we need our CoffeeValue helper class to have access to these variables when the chain moves.</p>
<p><strong>Chain, Chain, Chaaiiiin..</strong><br />
Below is the flow of the chain.</p>
<p><img src="http://asgerlaursen.com/wp-content/uploads/2009/28_01_2009/28-01-2009%2023-10-38.png" alt="Reverse Method Chain Flow" /></p>
<p>So to recap; The chain starts from the last part of the language, and what happens is, that each line in the Coffee order, which is actually a new CoffeeValue being instantiated, gets collected by the last object in the Chain, finally ending in the &#8220;latte&#8221; variable.</p>
<p>So lets see what is inside the CofeeValue class:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p108code13'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p10813"><td class="code" id="p108code13"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> CoffeeValue <span style="color: #0066CC;">extends</span> Coffee <span style="color: #0066CC;">implements</span> CoffeeSize, CoffeeType, Consumption, FatContent , Water, Temperature, ICoffeeValue
	<span style="color: #66cc66;">&#123;</span>
		protected <span style="color: #000000; font-weight: bold;">var</span> _value:<span style="color: #66cc66;">*</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _property:<span style="color: #0066CC;">String</span>;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> CoffeeValue<span style="color: #66cc66;">&#40;</span>property:<span style="color: #0066CC;">String</span>,value:<span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			_property = property;
			_value = value;
			<span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;_&quot;</span>+_property<span style="color: #66cc66;">&#93;</span> = <span style="color: #0066CC;">this</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		override <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> <span style="color: #0066CC;">size</span><span style="color: #66cc66;">&#40;</span>value:<span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
&nbsp;
			createRef<span style="color: #66cc66;">&#40;</span>value<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		override <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> <span style="color: #0066CC;">type</span><span style="color: #66cc66;">&#40;</span>value:<span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			createRef<span style="color: #66cc66;">&#40;</span>value<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		override <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> temperature<span style="color: #66cc66;">&#40;</span>value:<span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
&nbsp;
			createRef<span style="color: #66cc66;">&#40;</span>value<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		override <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> fat<span style="color: #66cc66;">&#40;</span>value:<span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
&nbsp;
			createRef<span style="color: #66cc66;">&#40;</span>value<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		override <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> water<span style="color: #66cc66;">&#40;</span>value:<span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			createRef<span style="color: #66cc66;">&#40;</span>value<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		override <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> where<span style="color: #66cc66;">&#40;</span>value:<span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			createRef<span style="color: #66cc66;">&#40;</span>value<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> value<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #66cc66;">*</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> _value;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> createRef<span style="color: #66cc66;">&#40;</span>assignee:<span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			assignee<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;_&quot;</span>+_property<span style="color: #66cc66;">&#93;</span> = <span style="color: #0066CC;">this</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p><strong>The trick</strong><br />
So in the CoffeeValue class we do the actual trick. As the class subclasses the Coffee, we override all the setting parts of our setter / getter properties in the Coffee. When we instantiate a CoffeeValue object, we pass two parameters:</p>
<p>1) is the textual name of the property our instance of the CoffeeValue is representing; in an example, if I wanted my object to be the value object for the water, I would pass &#8220;water&#8221; as the first parameter. </p>
<p>2)The next value is the actual value of the property, in our example I have kept it simple (or as simple as possible <img src='http://asgerlaursen.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> ) and just used strings, so in this context it would be &#8220;no water&#8221; as the value.<br />
Both parameters is saved for later. </p>
<p><strong>What??</strong><br />
So I mentioned the overriding of the setters. What each setter is doing, is calling a private method called &#8220;createRef&#8221;. What happens in the chain is that the various setters is being called by the various concrete classes. Thus, we need what ever calling class, which has assigned it self as value to the setter, to get it&#8217;s property set to the value the called class represents. Puuhhh, that was a tough sentence, but lets put some variables to it. Class&#8217;s type = A_TYPE&#8217;s size = B_SIZE&#8217;s temperature = C_TEMPERATURE. So in this expression, the A,B and C represents the Concrete implementations, which is just different pairs of parameters send to the CoffeeValue. So the chain starts from behind, and C is passed in to B&#8217;s set temperature, after that C is passed on to A&#8217;s type setter.</p>
<p>So what we make sure in the CoffeeValue setters, -> createRef, is that the class handling the setter, which knows which property it represents (remember it got that from the constructor) assigns it self to the object collecting stuff trough the chain (the last object in the expression or C in our above simplification).</p>
<p>The value parameter is simply saved and used as a easy way to retrieve the value of the CoffeeValue by a get value method.</p>
<p><strong>Concrete Concrete</strong><br />
Don&#8217;t worry, it takes a little to get your head around. - and we have yet not seen the actual implementation of a concrete class.<br />
In the DSL I have created the language constructs as &#8220;static constants&#8221; or that is what they look like at least.<br />
But lets dissect the ConcreteCoffeeSize class (you would of cause go about calling the classes some else than prefixing them with &#8220;concrete&#8221; but to illustrate what is what I have decided to do so).</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p108code14'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p10814"><td class="code" id="p108code14"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ConcreteCoffeeSize <span style="color: #0066CC;">extends</span> CoffeeValue
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> GRANDE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:CoffeeValue
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> ConcreteCoffeeSize<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;grande&quot;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> VENTI<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:CoffeeValue
		<span style="color: #66cc66;">&#123;</span> 
			<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> ConcreteCoffeeSize<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;venti&quot;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> ConcreteCoffeeSize<span style="color: #66cc66;">&#40;</span>value:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;size&quot;</span>,value<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>So worth noticing is that this simple class, which merely would normally be a class, has two static getters, each of them returning a new instance of ConcreteCoffeeSize, each with a different setting in value parameter. The constructor of the ConcreteCoffeeSize, is typed to handle the value, given, and providing the property which the class it self represents, to the super() constructor. You could of cause have tons of other logical things inside each concrete class, which differentiated the classes more than just a simple textual value. But for the simple example, and the fact that I&#8217;m not building a DSL for employees at StarBucks, I&#8217;m an settling for less this time <img src='http://asgerlaursen.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p><strong>Outro</strong><br />
I guess this wraps this bastard of a blog post up.<br />
Just to touch briefly on the Interfaces used, they are empty except the ICoffeeValue which defines the &#8220;get value&#8221; function implemented by CoffeeValue.<br />
There is a lot of great possibilities in using a reversed method chain, and definitely room for improvements in my above approach.</p>
<p>Feel free to ask or comment, if there is anything you want to dive into. - maybe you have an even easier way to accomplish the same structure.</p>
<p>Happy Coding</p>
<p>Cheers</p>
]]></content:encoded>
			<wfw:commentRss>http://asgerlaursen.com/2009/01/28/actionscript-ria-and-dsl-part-1-%c2%bd/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Cairngorm Confessions: The Journey</title>
		<link>http://asgerlaursen.com/2008/12/28/cairngorm-confessions-the-journey/</link>
		<comments>http://asgerlaursen.com/2008/12/28/cairngorm-confessions-the-journey/#comments</comments>
		<pubDate>Sun, 28 Dec 2008 22:45:26 +0000</pubDate>
		<dc:creator>Asger</dc:creator>
		
		<category><![CDATA[ActionScript]]></category>

		<category><![CDATA[Cairngorm]]></category>

		<category><![CDATA[Cairngorm Confessions]]></category>

		<category><![CDATA[Application Design]]></category>

		<category><![CDATA[Architecture]]></category>

		<category><![CDATA[Flex]]></category>

		<category><![CDATA[Framework]]></category>

		<category><![CDATA[Patterns]]></category>

		<guid isPermaLink="false">http://asgerlaursen.com/?p=42</guid>
		<description><![CDATA[Introduction
Ever felt that there was something wrong with the way you architected your application with the Cairngorm framework?
Well, I for sure have.
Motivation
The motivation for this Flexback Flashback blog-post about my way with Flex and Cairngorm derives from to concurrent events; I&#8217;m currently working as a consultant with some great Java and .NET guys. In this [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Introduction</strong><br />
Ever felt that there was something wrong with the way you architected your application with the Cairngorm framework?<br />
Well, I for sure have.</p>
<p><strong>Motivation</strong><br />
The motivation for this <del datetime="2008-12-19T13:37:30+00:00">Flexback</del> Flashback blog-post about my way with Flex and Cairngorm derives from to concurrent events; I&#8217;m currently working as a consultant with some great Java and .NET guys. In this project we have decided to use Cairngorm as our architectural framework, a decision I of cause is very happy about. In order to provide the team with an introduction to Cairngorm, I conducted a sample application to support my introduction. This process of going over the various points and parts of the framework led my thoughts back to my own path of learning and using Flex and Cairngorm (which I guess I&#8217;m still doing, and hopefully will continue to do). Simultaneously I had to present to a local Adobe RIA User Group meeting, and happened to get the same topic; &#8220;Cairngorm&#8221;. This concentration of going over Cairngorm and ways to apply it, cerated an overflow of thoughts and memories which is what this post is about. I&#8217;ll in the following try to show and tell about how I used Cairngorm, at different steps and level of understanding.</p>
<p><strong>The example domain</strong><br />
In use for my drive down memory lane I have created a business domain called &#8220;Cyber Wallet&#8221;. The business of Cyber Wallet is an online wallet application in which you can withdraw and deposit money. When ever you do either of the two you create a transaction with a time stamp associated with the money involved. A quick sketch of the Domain Model looks like this:<br />
<img class="alignnone" title="Cyber Wallet Domain Model" src="http://asgerlaursen.com/wp-content/uploads/2008/18/cyberWalletDomain.png" alt="" width="691" height="376" /><br />
So this being the simple Domain Model, we can continue on with the Use Cases in the Cyber Wallet application. I have narrowed them down to:</p>
<ol>
<li>Log In</li>
<li>Log Out</li>
<li>Deposit Money</li>
<li>Withdraw Money</li>
</ol>
<p>So we&#8217;ll take a look at some of these Domain Classes and the Use Cases implemented in various ways. Common for all the examples are that there is 3 main view parts:</p>
<ol>
<li>a Log In Panel, rendering what is related to authentication use cases (LogInPanel.mxml)</li>
<li>a Wallet Panel, rendering what is related to the wallet use cases (deposit and withdraw) (WalletPanel.mxml)</li>
<li>a Status Panel, rendering what is related to the running transactions related to the wallet use cases (StatusPanel.mxml)</li>
</ol>
<p>The Money and the Transaction classes will be the same trough out the examples and are implemented as the following:</p>
<p><strong>Money Class</strong></p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p42code27'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p4227"><td class="code" id="p42code27"><pre class="actionscript" style="font-family:monospace;">package model.<span style="color: #0066CC;">domain</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Money
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _amount:<span style="color: #0066CC;">Number</span>;
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _currency:<span style="color: #0066CC;">String</span>;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Money<span style="color: #66cc66;">&#40;</span>amount:<span style="color: #0066CC;">Number</span>,currency:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			_amount = amount;
			_currency = currency;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> amount<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Number</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> _amount;
		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> currency<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> _currency;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> _amount+ <span style="color: #ff0000;">&quot; &quot;</span>+_currency;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">add</span><span style="color: #66cc66;">&#40;</span>money:Money<span style="color: #66cc66;">&#41;</span>:Money
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">//TODO implement logic for adding money</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> Money<span style="color: #66cc66;">&#40;</span>_amount+money.<span style="color: #006600;">amount</span>,_currency<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> substract<span style="color: #66cc66;">&#40;</span>money:Money<span style="color: #66cc66;">&#41;</span>:Money
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">//TODO implement logic for subtracting money</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> Money<span style="color: #66cc66;">&#40;</span>_amount-money.<span style="color: #006600;">amount</span>,_currency<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> equals<span style="color: #66cc66;">&#40;</span>money:Money<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Boolean</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">//TODO implement logic to check for different currencies</span>
			<span style="color: #b1b100;">return</span> _amount == money.<span style="color: #006600;">amount</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p><strong>Transaction Class</strong></p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p42code28'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p4228"><td class="code" id="p42code28"><pre class="actionscript" style="font-family:monospace;">package model.<span style="color: #0066CC;">domain</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Transaction
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const DEPOSITE:<span style="color: #0066CC;">String</span> =<span style="color: #ff0000;">&quot;deposite&quot;</span>;
		<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const WITHDRAW:<span style="color: #0066CC;">String</span> =<span style="color: #ff0000;">&quot;withdraw&quot;</span>;
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _type:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _timeStamp:<span style="color: #0066CC;">Date</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _transactionNote:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _money:Money;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Transaction<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">type</span>:<span style="color: #0066CC;">String</span>,money:Money,notes:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			_type = <span style="color: #0066CC;">type</span>;
			_money = money;
			_transactionNote = notes;
			_timeStamp = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Date</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #ff0000;">&quot;START Transaction: -&amp;gt;&quot;</span>+_type.<span style="color: #0066CC;">toUpperCase</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>+<span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span>Date: &quot;</span>+_timeStamp.<span style="color: #0066CC;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>+<span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span>Amount:&quot;</span>+_money.<span style="color: #0066CC;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>+<span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span>&quot;</span> +
					<span style="color: #ff0000;">&quot;&quot;</span>+_transactionNote+<span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>END Transaction<span style="color: #000099; font-weight: bold;">\n</span>--------------------------------------<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p><strong>Perspective</strong><br />
To put things in perspective I&#8217;ll have to mention that I started out with developing larger applications (larger than the &#8220;hello world&#8221; app) in Flex at the same time that I started looking in to Cairngorm. So my experiences of one or the other could be an effect of the synergy at place when getting your hands to dirty at once.</p>
<p>I have always understood &#8220;Model&#8221; in the Model-View-Controller pattern to be equivalent to a Domain Model. This Domain-centric Model understanding really troubled my mind when I started looking in to Cairngorm. I felt that the best practices of Cairngorm violated my best practices in terms of having, and working with, real Domain concepts and models. Later I have learned that &#8220;Model&#8221; in MVC to some is understood as a Service Layer, Transaction Layer or simply a Domain Representation of the Domain Model (but not the actual Domain instance(s)). When looking back on how I at first tried to make Cairngorm work with my actual Domain layer, I clearly see a mixing of clean Domain Models and Domain Representations.</p>
<p><strong>Feeling of something being wrong</strong><br />
First time I got a sign of something being wrong was when I for the first time placed a [Bindable] tag inside a Domain Model object. Coming from the pure AS3 world where my Domain objects always had been nice and clean associated with one another as the would be reflected in the actual business domain, the whole concept of placing a &#8220;magic&#8221; tag on properties which other objects could bind to, felt wrong. Not the tag, and what the tag in isolation stood for (Broadcasting notification about property changes as any Observer pattern implementation), but what I could see would -, and soon did follow this way of binding view and model together (also; I was starting out in Flex, so messing my domain up, and making them useless for reuse in pure AS3 applications (what they would be, when depending on the [Bindable] tag) also felt bad - now I know I&#8217;ll never go back to pure AS3 though.. but I guess I needed the safety net if this &#8220;Flex thingie&#8221; didn&#8217;t turn out to be all that anyway <img src='http://asgerlaursen.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ).</p>
<p>What I experienced was that I started composing my models, besides being a reflection of the business domain, also being a reflection of what the view needed. For instance say I was building an application with a use case of a user logging ind, I would consider a User Domain Model object, with data related to the conceptual user. - but building the View (which I understood should bind to the model, hence my User) I would start saying <em>&#8220;what do I need in the view to make it run bound to the model? Oh well, I need some state information about whether the user is; logging in, logged in, logging out or logged out&#8221;</em>. And I would go about either having a string property on the User object, reflecting these states (which I didn&#8217;t like all that much) or build a supporting model like &#8220;AuthenticationManager&#8221; (early interpretation of my knowledge of a Presentation Model) merely just having the states of the logging in use case. In terms of the problems with the states I kind of felt that I was still within boundary of good practice, excusing my self; &#8220;most objects have states, also a user object, right!?!?&#8221;. - though I knew that my interpretation of states in an object was much different than just a property holding a string.</p>
<p><strong>Example 1</strong><br />
So given the above, I would properly go about creating my Wallet class like this:</p>
<p><strong>Wallet Class</strong></p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p42code29'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p4229"><td class="code" id="p42code29"><pre class="actionscript" style="font-family:monospace;">package model
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">collections</span>.<span style="color: #006600;">ArrayCollection</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Wallet
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const STATE_IN_TRANSACTION:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;stateInTransaction&quot;</span>;
		<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const STATE_IDLE:<span style="color: #0066CC;">String</span> =<span style="color: #ff0000;">&quot;stateIdle&quot;</span>;
&nbsp;
&nbsp;
		<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> balance:Money;
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> transactionLog:ArrayCollection;
&nbsp;
		<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> transactionNotes:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;&quot;</span>;
&nbsp;
		<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> state:<span style="color: #0066CC;">String</span> = STATE_IDLE;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Wallet<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			balance = <span style="color: #000000; font-weight: bold;">new</span> Money<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>,<span style="color: #ff0000;">&quot;dollars&quot;</span><span style="color: #66cc66;">&#41;</span>;
			transactionLog = <span style="color: #000000; font-weight: bold;">new</span> ArrayCollection<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> deposite<span style="color: #66cc66;">&#40;</span>money:Money,notes:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			balance = balance.<span style="color: #0066CC;">add</span><span style="color: #66cc66;">&#40;</span>money<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #000000; font-weight: bold;">var</span> trans:Transaction = <span style="color: #000000; font-weight: bold;">new</span> Transaction<span style="color: #66cc66;">&#40;</span>Transaction.<span style="color: #006600;">DEPOSITE</span>,money,notes<span style="color: #66cc66;">&#41;</span>;
			transactionLog.<span style="color: #006600;">addItem</span><span style="color: #66cc66;">&#40;</span>trans<span style="color: #66cc66;">&#41;</span>;
			transactionNotes+=trans.<span style="color: #0066CC;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> withdraw<span style="color: #66cc66;">&#40;</span>money:Money,notes:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			balance = balance.<span style="color: #006600;">substract</span><span style="color: #66cc66;">&#40;</span>money<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #000000; font-weight: bold;">var</span> trans:Transaction = <span style="color: #000000; font-weight: bold;">new</span> Transaction<span style="color: #66cc66;">&#40;</span>Transaction.<span style="color: #006600;">WITHDRAW</span>,money,notes<span style="color: #66cc66;">&#41;</span>;
			transactionLog.<span style="color: #006600;">addItem</span><span style="color: #66cc66;">&#40;</span>trans<span style="color: #66cc66;">&#41;</span>;
			transactionNotes+=trans.<span style="color: #0066CC;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Notice the [Bindable] tags on the balance and the transactionNotes properties. Beside these Domain related properties a state property and corresponding state constants has been declared as well. These would be used for the view to change to the appropriate View state, when the wallet changed.<br />
So a lot of View specific properties not really related to the Domain implementation of the Wallet.</p>
<p>When creating the WalletPanel in the application which would have the responsibility of render the amount of the Wallet to the screen, and providing controls for depositing and withdrawing money, we can now directly bind to the balance property of the Wallet.</p>
<p><strong>WalletPanel View</strong></p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p42code30'); return false;">View Code</a> MXML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p4230"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
</pre></td><td class="code" id="p42code30"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Panel</span> xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> height=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #339933;">&lt;mx:Script&gt;</span>
<span style="color: #339933;">    &lt;![CDATA[</span>
<span style="color: #339933;">        import event.WithdrawEvent;</span>
<span style="color: #339933;">        import event.DepositeEvent;</span>
<span style="color: #339933;">        import model.ModelLocator;</span>
&nbsp;
<span style="color: #339933;">        //No dependency injection, but directly accessing the ModelLocator</span>
<span style="color: #339933;">        [Bindable]</span>
<span style="color: #339933;">        private var _model:ModelLocator = ModelLocator.getInstance();</span>
<span style="color: #339933;">    ]]&gt;</span>
<span style="color: #339933;">&lt;/mx:Script&gt;</span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:VBox</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> height=<span style="color: #ff0000;">&quot;100%&quot;</span> horizontalAlign=<span style="color: #ff0000;">&quot;center&quot;</span> verticalAlign=<span style="color: #ff0000;">&quot;middle&quot;</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- Directly look up, in the model locator, </span>
<span style="color: #000000;">        ... to access the wallet's balance's amount and currency</span>
<span style="color: #000000;">         ... NOT a good approach for dynamic and reusable views --&gt;</span></span>
&nbsp;
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Label</span> text=<span style="color: #ff0000;">&quot;Wallet Balance is {_model.wallet.balance.amount +' '+ _model.wallet.balance.currency}&quot;</span> fontSize=<span style="color: #ff0000;">&quot;30&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:HBox</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> height=<span style="color: #ff0000;">&quot;100%&quot;</span> horizontalAlign=<span style="color: #ff0000;">&quot;center&quot;</span> verticalAlign=<span style="color: #ff0000;">&quot;middle&quot;</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:VBox</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> height=<span style="color: #ff0000;">&quot;100%&quot;</span> horizontalAlign=<span style="color: #ff0000;">&quot;center&quot;</span> verticalAlign=<span style="color: #ff0000;">&quot;middle&quot;</span><span style="color: #7400FF;">&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:TextInput</span> restrict=<span style="color: #ff0000;">&quot;0-9&quot;</span> id=<span style="color: #ff0000;">&quot;depositeInput&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Button</span> label=<span style="color: #ff0000;">&quot;Deposite&quot;</span><span style="color: #7400FF;">&gt;</span></span>
                    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:click</span><span style="color: #7400FF;">&gt;</span></span>
                        <span style="color: #000000;">&lt;!<span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span></span>
&nbsp;
<span style="color: #000000;">                            // Directly dispatching of Cairngorm <span style="color: #66cc66;">&#40;</span>Use Case<span style="color: #66cc66;">&#41;</span> events from within the view</span>
<span style="color: #000000;">                            var de:DepositeEvent = new DepositeEvent<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">                            de.data = Number<span style="color: #66cc66;">&#40;</span>depositeInput.text<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">                            de.dispatch<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">                        <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #7400FF;">&gt;</span></span>
                    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:click</span><span style="color: #7400FF;">&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Button</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:VBox</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:VBox</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> height=<span style="color: #ff0000;">&quot;100%&quot;</span> horizontalAlign=<span style="color: #ff0000;">&quot;center&quot;</span> verticalAlign=<span style="color: #ff0000;">&quot;middle&quot;</span><span style="color: #7400FF;">&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:TextInput</span> restrict=<span style="color: #ff0000;">&quot;0-9&quot;</span> id=<span style="color: #ff0000;">&quot;withdrawInput&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Button</span> label=<span style="color: #ff0000;">&quot;Withdraw&quot;</span><span style="color: #7400FF;">&gt;</span></span>
                    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:click</span><span style="color: #7400FF;">&gt;</span></span>
                        <span style="color: #000000;">&lt;!<span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span></span>
&nbsp;
<span style="color: #000000;">                            // Directly dispatching of Cairngorm <span style="color: #66cc66;">&#40;</span>Use Case<span style="color: #66cc66;">&#41;</span> events from within the view</span>
<span style="color: #000000;">                            var we:WithdrawEvent = new WithdrawEvent<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">                            we.data = Number<span style="color: #66cc66;">&#40;</span>withdrawInput.text<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">                            we.dispatch<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">                        <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #7400FF;">&gt;</span></span>
                    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:click</span><span style="color: #7400FF;">&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Button</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:VBox</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:HBox</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:VBox</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Panel</span><span style="color: #7400FF;">&gt;</span></span></pre></td></tr></table></div>

<p>Okay, to touch on some practices, I have in the above MXML component (and in the rest of the examples) really made an effort in showing some critical points where you should watch how you implement your rendering in the view.<br />
First is the lack of dependency injection; I directly reference the ModelLocator to retrieve the instance of wallet. This is not a favorable approach, as this couples our view unnecessary to the Cairngorm framework (The ModelLocator pattern) - also by not having the dependent Wallet injected at runtime, we miss the opportunity of resetting the component later, by injecting a new Wallet.</p>
<p>Furthermore the DepositeEvent and WithdrawEvent, which is CairngormEvents representing application Use Case Events, are created and dispatched directly from WalletPanel. This approach presents some problems; again the coupling between the view and Cairngorm is unnecessary and our view would not be reusable in another application without modification. Another more underlying thing is that there is no other mediator between views than the actual Domain Model objects. So every change in our view, which might be of interest to other views, would have to be reflected in the Domain Model and the update in the view would have to be related to a Use Case/ CairngormEvent and trigger a around trip in the application(Event -&gt; Controller -&gt; Command -&gt; Model -&gt; View).<br />
To give an overview of what I mean, you should take a look at the below diagram:</p>
<p><em>A UML diagram of the structure of the application</em><br />
<img class="alignnone size-full wp-image-64" title="ex1diagram" src="http://asgerlaursen.com/wp-content/uploads/2008/12/ex1Diagram.png" alt="ex1diagram" width="673" height="1081" /></p>
<p>Here is the <a href="http://asgerlaursen.com/wp-content/uploads/2008/18/ex1/index.html" >CyberWallet application</a> implemented with the above state of mind. You can view the source by right clicking and choosing &#8220;View Source&#8221;.  Bear in mind that the application is not created to show case Flex specific things, and *yes* I know a lot could have been done smarter, better, easier,&#8230; etc. - these things is not the focus of this post. But what you *should* notice is the way Cairngorm is setup, and how the view retrieves the Model, how it communicates with the controller layer and how the Model is implemented to provide view-centric/specific needs.<br />
I wont go over the other use cases and view parts, as you can see them for your self, in the source. I have commented here and there to point out the violations mentioned above.</p>
<p><strong>The next big step</strong><br />
After working around for some time, getting more and more familiar with Flex and of cause Cairngorm, I started getting rid of some of the &#8220;teething troubles&#8221;. All the apparent issues from the example above; better dependency injection, decoupling between view and Cairngorm and a better formalization and evolution of the supporting model objects (-managing, -monitoring &#8230;). I started looking at these classes or coherent collections of responsibility as representational model objects; representational in the way, that these objects would represent smaller or larger parts of the Domain, without being an actual Domain Model them selves. If I today should categorize them I would say that they where &#8220;Passive Presentational Models&#8221; or &#8220;Ultra Thin Presentational Models&#8221;. - if you are not familiar with Martin Fowlers work on &#8220;<a href="http://martinfowler.com/eaaDev/OrganizingPresentations.html" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://martinfowler.com/eaaDev/OrganizingPresentations.html');">Organizing presentation logic</a>&#8220;, you should definitely take at look.</p>
<p>This way of moving away from having view-needed properties in the Domain, and instead having coherent parts of the Domain represented in &#8220;Thin Presentation Models&#8221; felt better. &#8220;A snake in paradise&#8221;- as my architecture started looking better when facing the model layer, I had started getting a lot of concerns in terms of how much logic to have in the Views. I had tried code behind for a while, which I really didn&#8217;t like due to the strong coupling, I turned to a more &#8220;View Helper&#8221; centric approach, where a view would have a helping class, handling events, states etc. - they never really felt like the best solution, and even though it wasn&#8217;t coupled trough inheritance like Code Behind, but trough composition, I had the same &#8220;to tight coupled&#8221; feeling as I had with Code Behind.</p>
<p>Another thing I didn&#8217;t like was the &#8220;one view, one helper&#8221; situation. -I really wanted to find a pattern where multiple views could feed from the same &#8220;source&#8221;. So I actually returned to putting logic back to the view. I started using an &#8220;Aggregated  View&#8221; pattern (there is no such pattern, but I invented the term internaly when talking about this aproach), where I would declare the new  Cairngorm-decoupled, reusable view components. These view components would depend on a &#8220;Thin Presentation Model&#8221; and be structured inside a custom wrapping view managing multiple components; hence the name &#8220;Aggregated View&#8221;. The idea was to have as much reusable code in coherent components, and let the &#8220;Aggregated View&#8221; handle the dependency injection, and gathering component level events, and interpreted them into use case events / CairngormEvents if necessary. This way the custom code would be minimized to evolve around setting up the reusable components, and only be inside these AggregatedView phenomenoms.</p>
<p><strong>Example 2</strong><br />
From example 1, to 2, there is two very distinct points I would like to iterate over. First I will take a look at how the Domain Model is held clean, and the use of the &#8220;Thin Presentation Model&#8221; - called Representation i the following, as it is not an actual implementation of the Presentation Model pattern.<br />
Next I&#8217;ll look at the &#8220;Aggregated View&#8221; I mentioned before, to show how our custom have been limited to a central mxml file (view).</p>
<p><strong>The Wallet revisited</strong><br />
Lets start by looking at the revisited Wallet class in the Domain layer. What you should notice is the total removal of [Bindable] tags. As mentioned earlier, I&#8217;m not a big fan of these in Domain Models. Instead you&#8217;ll see that the Wallet now is an EventDispatcher descendant, and that I have introduced a TransactionEvent, being fired when ever a Transaction has occurred in the Wallet. The state property is gone as is the transactionNotes. These responsibilities would now be found in the Representation of the Wallet. This way of having the Domain Cleaned out, only using pure ActionScript features such as dispatching events etc, is how I still is implementing my Domain Models today.</p>
<p><strong>Wallet Class</strong></p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p42code31'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p4231"><td class="code" id="p42code31"><pre class="actionscript" style="font-family:monospace;">package model.<span style="color: #0066CC;">domain</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> event.<span style="color: #006600;">TransactionEvent</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">EventDispatcher</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">collections</span>.<span style="color: #006600;">ArrayCollection</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Wallet <span style="color: #0066CC;">extends</span> EventDispatcher
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> balance:Money;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> transactionLog:ArrayCollection;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Wallet<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			balance = <span style="color: #000000; font-weight: bold;">new</span> Money<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>,<span style="color: #ff0000;">&quot;dollars&quot;</span><span style="color: #66cc66;">&#41;</span>;
			transactionLog = <span style="color: #000000; font-weight: bold;">new</span> ArrayCollection<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> deposit<span style="color: #66cc66;">&#40;</span>money:Money,notes:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			balance = balance.<span style="color: #0066CC;">add</span><span style="color: #66cc66;">&#40;</span>money<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #000000; font-weight: bold;">var</span> trans:Transaction = <span style="color: #000000; font-weight: bold;">new</span> Transaction<span style="color: #66cc66;">&#40;</span>Transaction.<span style="color: #006600;">DEPOSITE</span>,money,notes<span style="color: #66cc66;">&#41;</span>;
			transactionLog.<span style="color: #006600;">addItem</span><span style="color: #66cc66;">&#40;</span>trans<span style="color: #66cc66;">&#41;</span>;
			dispatchTransaction<span style="color: #66cc66;">&#40;</span>trans<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> withdraw<span style="color: #66cc66;">&#40;</span>money:Money,notes:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			balance = balance.<span style="color: #006600;">substract</span><span style="color: #66cc66;">&#40;</span>money<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #000000; font-weight: bold;">var</span> trans:Transaction = <span style="color: #000000; font-weight: bold;">new</span> Transaction<span style="color: #66cc66;">&#40;</span>Transaction.<span style="color: #006600;">WITHDRAW</span>,money,notes<span style="color: #66cc66;">&#41;</span>;
			transactionLog.<span style="color: #006600;">addItem</span><span style="color: #66cc66;">&#40;</span>trans<span style="color: #66cc66;">&#41;</span>;
			dispatchTransaction<span style="color: #66cc66;">&#40;</span>trans<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> dispatchTransaction<span style="color: #66cc66;">&#40;</span>t:Transaction<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> te:TransactionEvent = <span style="color: #000000; font-weight: bold;">new</span> TransactionEvent<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;transaction&quot;</span><span style="color: #66cc66;">&#41;</span>;
			te.<span style="color: #006600;">transaction</span> = t;
			dispatchEvent<span style="color: #66cc66;">&#40;</span>te<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p><strong>The EconomyRepresentation</strong><br />
So getting rid of the view and Flex specific noise in the Domain, we can now take a look at the new Representation class used to provide the view specific information from the Wallet. Instead of naming my Representation something like WalletRepresentation, which would remind me to much of the one - to -one mapping in the View Helper pattern, I would name it EconomyRepresentation. As stated, my hope was to move towards a set of patterns giving my a central coherent place for multiple views to subscribe to Domain data. - thus, by going for a broader Representation term, and also the responsibility, I would get a class which could serve all views with interest in presenting parts of the aggregated Domain related to economy.</p>
<p><strong>EconomyRepresentation Class</strong></p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p42code32'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p4232"><td class="code" id="p42code32"><pre class="actionscript" style="font-family:monospace;">&nbsp;
package model.<span style="color: #006600;">presentation</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> event.<span style="color: #006600;">TransactionEvent</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> model.<span style="color: #0066CC;">domain</span>.<span style="color: #006600;">Wallet</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> EconomyRepresentation
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> transactionLog:<span style="color: #0066CC;">String</span> =<span style="color: #ff0000;">&quot;&quot;</span>;
&nbsp;
		<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> balance:<span style="color: #0066CC;">String</span>;
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _wallet:Wallet;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> EconomyRepresentation<span style="color: #66cc66;">&#40;</span>wallet:Wallet<span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			_wallet = wallet;
			init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			balance = _wallet.<span style="color: #006600;">balance</span>.<span style="color: #0066CC;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			_wallet.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;transaction&quot;</span>,walletTransactionHandler<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> walletTransactionHandler<span style="color: #66cc66;">&#40;</span>te:TransactionEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			transactionLog+= te.<span style="color: #006600;">transaction</span>.<span style="color: #0066CC;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			balance = _wallet.<span style="color: #006600;">balance</span>.<span style="color: #0066CC;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>As you can see, the EconomyRepresentation has a reference to the Wallet Domain object. It subscribes to the transaction event broadcasted by Wallet. When this broadcast is handled the EconomyRepresentation updates it&#8217;s balance, which compared to the balance of Wallet, is just a string, and the transactionLog compared to the transactionLog in Wallet which is of type ArrayCollection, is again just a string representing the log of the Wallet.<br />
As I think this way of cleaning and separating (re)Presentational logic from the Domain is very essential, I&#8217;ll show you the AuthenticationRepresentation and the ApplicationRepresentation as well. These two classes is of cause used to represent the authentication related data and state of the application and the state of the actual-application (actual-application; the overall state of the application). The latter being the workflowState declared directly on the ModelLocator in Example 1 (run the example and view the source).</p>
<p><strong>AuthenticationRepresentation Class</strong></p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p42code33'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p4233"><td class="code" id="p42code33"><pre class="actionscript" style="font-family:monospace;">package model.<span style="color: #006600;">presentation</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">EventDispatcher</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> AuthenticationRepresentation <span style="color: #0066CC;">extends</span> EventDispatcher
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const LOGGING_IN:<span style="color: #0066CC;">String</span> =<span style="color: #ff0000;">&quot;loggingIn&quot;</span>;
		<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const LOGGED_IN:<span style="color: #0066CC;">String</span> =<span style="color: #ff0000;">&quot;loggedIn&quot;</span>;
		<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const LOGGING_OUT:<span style="color: #0066CC;">String</span> =<span style="color: #ff0000;">&quot;loggingOut&quot;</span>;
		<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const LOGGED_OUT:<span style="color: #0066CC;">String</span> =<span style="color: #ff0000;">&quot;loggedOut&quot;</span>;
		<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const LOGGING_IN_FAULT:<span style="color: #0066CC;">String</span> =<span style="color: #ff0000;">&quot;loggingInFault&quot;</span>;
&nbsp;
		<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> state:<span style="color: #0066CC;">String</span> = LOGGED_OUT;
&nbsp;
		<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> userName:<span style="color: #0066CC;">String</span>;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> AuthenticationRepresentation<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
&nbsp;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>The above is simply just the states we had in the AuthenticationManager plus the userName property.</p>
<p>But what is interesting is to be seen in the following example of the ApplicationRepresentation class</p>
<p><strong>ApplicationRepresentation Class</strong></p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p42code34'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p4234"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
</pre></td><td class="code" id="p42code34"><pre class="actionscript" style="font-family:monospace;">package model.<span style="color: #006600;">presentation</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> model.<span style="color: #006600;">ModelLocator</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">events</span>.<span style="color: #006600;">PropertyChangeEvent</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ApplicationRepresentation
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const AUTHENTICATION:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;authentication&quot;</span>;
		<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const IDLE:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;idle&quot;</span>;
&nbsp;
		<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> state:<span style="color: #0066CC;">String</span> = AUTHENTICATION;
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _authModel:AuthenticationRepresentation;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> ApplicationRepresentation<span style="color: #66cc66;">&#40;</span>authModel:AuthenticationRepresentation<span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			_authModel = authModel;
			init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			_authModel.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>PropertyChangeEvent.<span style="color: #006600;">PROPERTY_CHANGE</span>,authModelChanged<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> authModelChanged<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:PropertyChangeEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #006600;">newValue</span> == <span style="color: #ff0000;">&quot;loggedIn&quot;</span><span style="color: #66cc66;">&#41;</span>
				state = IDLE;
			<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #006600;">newValue</span> ==<span style="color: #ff0000;">&quot;loggedOut&quot;</span><span style="color: #66cc66;">&#41;</span>
				state = AUTHENTICATION;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>- the ApplicationRepresentation is dependent on another Representation, to manage it&#8217;s states. This is for me a vital feature in the design; being able to structure hierarchical Representations of the Domain. If you look at the source of Example 1 you would see that in the LogInCommand I would manipulate both the state of the AuthenticationManager *and* the workflowState property of the ModelLocator. To me, it is more sound to have an association-structure among these Representation models, as we have it at the Domain level of the model. Instead of having our controller feature of the architecture coupled to how our representation is laid out, the LogInCommand should only worry (and know) Representation and/or Domain objects related to pure concept of &#8220;Loggin In&#8221; - and not derivations!</p>
<p><strong>The Aggregated View</strong><br />
As we looked at the WalletPanel in example 1, I&#8217;ll take my point in the same view part here. - the rest of the view implementations can been seen by running the example linked to below, and selecting to view the source.</p>
<p><strong>WalletPanel View</strong></p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p42code35'); return false;">View Code</a> MXML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p4235"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
</pre></td><td class="code" id="p42code35"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Panel</span> xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> height=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Metadata</span><span style="color: #7400FF;">&gt;</span></span>
    [Event(name=&quot;withdraw&quot;)]
    [Event(name=&quot;deposite&quot;)]
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Metadata</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #339933;">&lt;mx:Script&gt;</span>
<span style="color: #339933;">    &lt;![CDATA[</span>
&nbsp;
<span style="color: #339933;">        //Balance is dependent on injection, instead of self-retrieved the data.</span>
<span style="color: #339933;">        [Bindable]</span>
<span style="color: #339933;">        public var balance:String</span>
&nbsp;
<span style="color: #339933;">        public var depositAmount:Number;</span>
&nbsp;
<span style="color: #339933;">        public var withdrawAmount:Number;</span>
<span style="color: #339933;">    ]]&gt;</span>
<span style="color: #339933;">&lt;/mx:Script&gt;</span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:VBox</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> height=<span style="color: #ff0000;">&quot;100%&quot;</span> horizontalAlign=<span style="color: #ff0000;">&quot;center&quot;</span> verticalAlign=<span style="color: #ff0000;">&quot;middle&quot;</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Label</span> text=<span style="color: #ff0000;">&quot;Wallet Balance is {balance}&quot;</span> fontSize=<span style="color: #ff0000;">&quot;30&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:HBox</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> height=<span style="color: #ff0000;">&quot;100%&quot;</span> horizontalAlign=<span style="color: #ff0000;">&quot;center&quot;</span> verticalAlign=<span style="color: #ff0000;">&quot;middle&quot;</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:VBox</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> height=<span style="color: #ff0000;">&quot;100%&quot;</span> horizontalAlign=<span style="color: #ff0000;">&quot;center&quot;</span> verticalAlign=<span style="color: #ff0000;">&quot;middle&quot;</span><span style="color: #7400FF;">&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:TextInput</span> restrict=<span style="color: #ff0000;">&quot;0-9&quot;</span> id=<span style="color: #ff0000;">&quot;depositeInput&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Button</span> label=<span style="color: #ff0000;">&quot;Deposit&quot;</span><span style="color: #7400FF;">&gt;</span></span>
                    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:click</span><span style="color: #7400FF;">&gt;</span></span>
                        <span style="color: #000000;">&lt;!<span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span></span>
<span style="color: #000000;">                            depositAmount = Number<span style="color: #66cc66;">&#40;</span>depositeInput.text<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">                            dispatchEvent<span style="color: #66cc66;">&#40;</span>new Event<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;deposite&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></span>
<span style="color: #000000;">                        <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #7400FF;">&gt;</span></span>
                    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:click</span><span style="color: #7400FF;">&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Button</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:VBox</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:VBox</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> height=<span style="color: #ff0000;">&quot;100%&quot;</span> horizontalAlign=<span style="color: #ff0000;">&quot;center&quot;</span> verticalAlign=<span style="color: #ff0000;">&quot;middle&quot;</span><span style="color: #7400FF;">&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:TextInput</span> restrict=<span style="color: #ff0000;">&quot;0-9&quot;</span> id=<span style="color: #ff0000;">&quot;withdrawInput&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Button</span> label=<span style="color: #ff0000;">&quot;Withdraw&quot;</span><span style="color: #7400FF;">&gt;</span></span>
                    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:click</span><span style="color: #7400FF;">&gt;</span></span>
                        <span style="color: #000000;">&lt;!<span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span></span>
<span style="color: #000000;">                            withdrawAmount = Number<span style="color: #66cc66;">&#40;</span>withdrawInput.text<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">                            dispatchEvent<span style="color: #66cc66;">&#40;</span>new Event<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;withdraw&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></span>
<span style="color: #000000;">                        <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #7400FF;">&gt;</span></span>
                    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:click</span><span style="color: #7400FF;">&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Button</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:VBox</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:HBox</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:VBox</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Panel</span><span style="color: #7400FF;">&gt;</span></span></pre></td></tr></table></div>

<p>If we look at the above, we see that the WalletPanel firstly defines some component-context events in the metatags, and that there is no dispatching of CairngormEvents from inhere anymore. This separation keeps the WalletPanel decoupled from the CairngormEvents, and instead we are able to handle the two component-defined events as we want out side of the component (for instance mapping them to CairngomEvents/use cases). Next, the balance property is declared as bindable thus making it an injection hole from the outside world, into the WalletPanel. The WalletPanel do not have to rely on the ModelLocator or any Domain Models to get its data; it simply expects it to be injected. In a matter of convenience I have provided the WalletPanel with two public properties, used by the outside world to retrieve the deposit and withdraw amounts respectively.<br />
To make this new revision of the WalletPanel, and the other new view components work, we need to look at our &#8220;AggregatedView&#8221;. In Example 1, we already had a view class aggregating and laying out the components; the LayoutView.</p>
<p>The LayoutView has in this example been modified to hold the application-specific code gluing the cleaner panel components and the representations together. The LayoutView works as a Mediator for the containing components, and injects their dependencies when declaring them. Lastly it handles the component-specific and dispatches the equivalent Use Case events (CairngormEvents).</p>
<p><strong>LayoutView</strong></p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p42code36'); return false;">View Code</a> MXML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p4236"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
</pre></td><td class="code" id="p42code36"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:HBox</span> xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> </span>
<span style="color: #000000;">    height=<span style="color: #ff0000;">&quot;100%&quot;</span> xmlns:login=<span style="color: #ff0000;">&quot;view.login.*&quot;</span> xmlns:status=<span style="color: #ff0000;">&quot;view.status.*&quot;</span> </span>
<span style="color: #000000;">    xmlns:wallet=<span style="color: #ff0000;">&quot;view.wallet.*&quot;</span></span>
<span style="color: #000000;">    currentState=<span style="color: #ff0000;">&quot;{_model.applicationModel.state}&quot;</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #339933;">&lt;mx:Script&gt;</span>
<span style="color: #339933;">    &lt;![CDATA[</span>
<span style="color: #339933;">        import event.WithdrawEvent;</span>
<span style="color: #339933;">        import event.DepositEvent;</span>
<span style="color: #339933;">        import event.LogOutEvent;</span>
<span style="color: #339933;">        import vo.UserVO;</span>
<span style="color: #339933;">        import event.LogInEvent;</span>
<span style="color: #339933;">        import model.ModelLocator;</span>
<span style="color: #339933;">        [Bindable]</span>
<span style="color: #339933;">        private var _model:ModelLocator = ModelLocator.getInstance();</span>
&nbsp;
<span style="color: #339933;">        private function handleLogIn(event:Event):void</span>
<span style="color: #339933;">        {</span>
<span style="color: #339933;">            var user:UserVO = new UserVO();</span>
<span style="color: #339933;">            user.userName = loginPanel.user;</span>
<span style="color: #339933;">            user.password = loginPanel.pass;</span>
<span style="color: #339933;">            var loginEvent:LogInEvent = new LogInEvent();</span>
<span style="color: #339933;">            loginEvent.data = user;</span>
<span style="color: #339933;">            loginEvent.dispatch();</span>
<span style="color: #339933;">        }</span>
<span style="color: #339933;">        private function handleLogOut(event:Event):void</span>
<span style="color: #339933;">        {</span>
<span style="color: #339933;">            new LogOutEvent().dispatch();</span>
<span style="color: #339933;">        }</span>
<span style="color: #339933;">        private function handleDeposit(event:Event):void</span>
<span style="color: #339933;">        {</span>
<span style="color: #339933;">            var de:DepositEvent = new DepositEvent();</span>
<span style="color: #339933;">            de.data = walletPanel.depositAmount;</span>
<span style="color: #339933;">            de.dispatch();</span>
<span style="color: #339933;">        }</span>
<span style="color: #339933;">        private function handleWithdraw(event:Event):void</span>
<span style="color: #339933;">        {</span>
<span style="color: #339933;">            var we:WithdrawEvent = new WithdrawEvent();</span>
<span style="color: #339933;">            we.data = walletPanel.withdrawAmount;</span>
<span style="color: #339933;">            we.dispatch();</span>
<span style="color: #339933;">        }</span>
<span style="color: #339933;">    ]]&gt;</span>
<span style="color: #339933;">&lt;/mx:Script&gt;</span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:VBox</span> id=<span style="color: #ff0000;">&quot;leftPanel&quot;</span> horizontalAlign=<span style="color: #ff0000;">&quot;center&quot;</span> horizontalCenter=<span style="color: #ff0000;">&quot;0&quot;</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;status:StatusPanel</span> id=<span style="color: #ff0000;">&quot;statusPanel&quot;</span> statusLog=<span style="color: #ff0000;">&quot;{_model.ecoModel.transactionLog}&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;login:LogInPanel</span> id=<span style="color: #ff0000;">&quot;loginPanel&quot;</span> authenticationModel=<span style="color: #ff0000;">&quot;{_model.authenticationModel}&quot;</span> </span>
<span style="color: #000000;">            logIn=<span style="color: #ff0000;">&quot;handleLogIn(event)&quot;</span></span>
<span style="color: #000000;">            logOut=<span style="color: #ff0000;">&quot;handleLogOut(event)&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:VBox</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;wallet:WalletPanel</span> id=<span style="color: #ff0000;">&quot;walletPanel&quot;</span> balance=<span style="color: #ff0000;">&quot;{_model.ecoModel.balance}&quot;</span> </span>
<span style="color: #000000;">        deposite=<span style="color: #ff0000;">&quot;handleDeposit(event)&quot;</span> withdraw=<span style="color: #ff0000;">&quot;handleWithdraw(event)&quot;</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/wallet:WalletPanel</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:states</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:State</span> name=<span style="color: #ff0000;">&quot;authentication&quot;</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:SetProperty</span> target=<span style="color: #ff0000;">&quot;{statusPanel}&quot;</span> name=<span style="color: #ff0000;">&quot;width&quot;</span> value=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:SetProperty</span> target=<span style="color: #ff0000;">&quot;{statusPanel}&quot;</span> name=<span style="color: #ff0000;">&quot;height&quot;</span> value=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:SetProperty</span> target=<span style="color: #ff0000;">&quot;{walletPanel}&quot;</span> name=<span style="color: #ff0000;">&quot;width&quot;</span> value=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:SetProperty</span> target=<span style="color: #ff0000;">&quot;{walletPanel}&quot;</span> name=<span style="color: #ff0000;">&quot;height&quot;</span> value=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:SetProperty</span> target=<span style="color: #ff0000;">&quot;{leftPanel}&quot;</span> name=<span style="color: #ff0000;">&quot;width&quot;</span> value=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:SetProperty</span> target=<span style="color: #ff0000;">&quot;{leftPanel}&quot;</span> name=<span style="color: #ff0000;">&quot;height&quot;</span> value=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:SetProperty</span> target=<span style="color: #ff0000;">&quot;{loginPanel}&quot;</span> name=<span style="color: #ff0000;">&quot;width&quot;</span> value=<span style="color: #ff0000;">&quot;25%&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:SetProperty</span> target=<span style="color: #ff0000;">&quot;{loginPanel}&quot;</span> name=<span style="color: #ff0000;">&quot;height&quot;</span> value=<span style="color: #ff0000;">&quot;25%&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:State</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:State</span> name=<span style="color: #ff0000;">&quot;idle&quot;</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:SetProperty</span> target=<span style="color: #ff0000;">&quot;{statusPanel}&quot;</span> name=<span style="color: #ff0000;">&quot;width&quot;</span> value=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:SetProperty</span> target=<span style="color: #ff0000;">&quot;{statusPanel}&quot;</span> name=<span style="color: #ff0000;">&quot;height&quot;</span> value=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:SetProperty</span> target=<span style="color: #ff0000;">&quot;{walletPanel}&quot;</span> name=<span style="color: #ff0000;">&quot;width&quot;</span> value=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:SetProperty</span> target=<span style="color: #ff0000;">&quot;{walletPanel}&quot;</span> name=<span style="color: #ff0000;">&quot;height&quot;</span> value=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:SetProperty</span> target=<span style="color: #ff0000;">&quot;{leftPanel}&quot;</span> name=<span style="color: #ff0000;">&quot;width&quot;</span> value=<span style="color: #ff0000;">&quot;25%&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:SetProperty</span> target=<span style="color: #ff0000;">&quot;{leftPanel}&quot;</span> name=<span style="color: #ff0000;">&quot;height&quot;</span> value=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:State</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:states</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:transitions</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Transition</span> fromState=<span style="color: #ff0000;">&quot;*&quot;</span> toState=<span style="color: #ff0000;">&quot;*&quot;</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Resize</span> targets=<span style="color: #ff0000;">&quot;{[walletPanel,leftPanel,statusPanel,loginPanel]}&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Transition</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:transitions</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:HBox</span><span style="color: #7400FF;">&gt;</span></span></pre></td></tr></table></div>

<p>Here is an overview of the application in UML. I have in the diagram also showed the Business package, which is not implemented in the example. This is only to show how it would have been implemented until now. A Command would instantiate a Delegate, which would use a service found in the ServiceLocator. The Delegate would be the first to handle the result back from the Service, massaging it in any way needed for the application. This could for instance be an XML stream needed to be parsed to the equivalent object hierarchy. After this, if any, data massaging the data would be send back to the Command, as a response. This way the only place where a Service and raw data manipulation would be at place, would be in the Delegate classes.</p>
<p><img class="alignnone" title="cyberwallet step 2 UML" src="http://asgerlaursen.com/wp-content/uploads/2008/12/cyberWallet%202.png" alt="" width="954" height="1516" /></p>
<p>You can see the example and view the source <a href="http://asgerlaursen.com/wp-content/uploads/2008/18/ex2/CyberWalletStep2.html" >here</a>.<br />
Key points in this example was the cleaning of the Domain layer and the more powerful Representation models. The view also got cleaner and an &#8220;AggregatedView&#8221; gluing it all together, providing injection and providing mediation between Views was created.</p>
<p><strong>The real Presentation Model<br />
</strong>At this time in my Cairngorm journey I started feeling good again about my work as an Architect , or as <a href="http://blog.benstucki.net" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://blog.benstucki.net');">Ben Stucki</a> might have put it; I started to move my Developer &lt;-&gt; Architect slider thumb, more towards the Architect end again (see <a href="http://link.brightcove.com/services/link/bcpid1733261879/bclid1729365228/bctid1741212613?src=mrss" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://link.brightcove.com/services/link/bcpid1733261879/bclid1729365228/bctid1741212613?src=mrss');">Bens&#8217;s great talk about Developers and Architects</a>). The way the cleaning of the Domain layer had turned out, was satisfying and reusable components decoupled from their surroundings also felt good. My own interpretation of a Presentation Model aka Representations also did the job good, and abstracted the Domain towards the view. But I still felt I had two challenges: My AggregatedViews also got the job done but their internals was not a pretty sight; custom code gluing it all together, seamed to call for a bloated script tag inside the MXML file. - further I still wasn&#8217;t to happy about the View. As mentioned I went back towards the <a href="http://weblogs.macromedia.com/paulw/archives/2007/09/presentation_pa_1.html" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://weblogs.macromedia.com/paulw/archives/2007/09/presentation_pa_1.html');">Autonomous View </a> pattern. -where a view manages it&#8217;s own presentation logic and state (or greater parts of it, as in example 2).</p>
<p>So the next step on my journey was to take a deeper look at the *real* Presentation Model, which fitted good into my current setup:</p>
<ol>
<li>My currently implemented Representation layer could easyli evolve into a real Presentation Model</li>
<li>My AggregatedView could be cleaned and the Presentation Model could encapsulate the component/use case specific code, and mediate for multiple views</li>
<li>My semi- Autonomous View could have it&#8217;s logic extracted and be a &#8220;dumb view&#8221; not knowing to much.</li>
</ol>
<p>So by evolving my Representation into a Presentation I could get closer to a solution to the two above mentioned challenges.</p>
<p><strong>Example 3<br />
</strong>To illustarate how to move the logic from  the View into a Presentation Model, I&#8217;ll return show how the Authentication Representation class ended up, as Authentication Model:</p>
<p><strong>AuthenticationModel Class</strong></p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p42code37'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p4237"><td class="code" id="p42code37"><pre class="actionscript" style="font-family:monospace;">package model.<span style="color: #006600;">presentation</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> event.<span style="color: #006600;">LogInEvent</span>;
	<span style="color: #0066CC;">import</span> event.<span style="color: #006600;">LogOutEvent</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">EventDispatcher</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> vo.<span style="color: #006600;">UserVO</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> AuthenticationModel <span style="color: #0066CC;">extends</span> EventDispatcher
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const LOGGING_IN:<span style="color: #0066CC;">String</span> =<span style="color: #ff0000;">&quot;loggingIn&quot;</span>;
		<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const LOGGED_IN:<span style="color: #0066CC;">String</span> =<span style="color: #ff0000;">&quot;loggedIn&quot;</span>;
		<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const LOGGING_OUT:<span style="color: #0066CC;">String</span> =<span style="color: #ff0000;">&quot;loggingOut&quot;</span>;
		<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const LOGGED_OUT:<span style="color: #0066CC;">String</span> =<span style="color: #ff0000;">&quot;loggedOut&quot;</span>;
		<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const LOGGING_IN_FAULT:<span style="color: #0066CC;">String</span> =<span style="color: #ff0000;">&quot;loggingInFault&quot;</span>;
&nbsp;
		<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> canLogIn:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">false</span>;
&nbsp;
		<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">status</span>:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;&quot;</span>;
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _userName:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _userNameIsValid:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">false</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _password:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _passwordIsValid:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">false</span>;
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _currentState:<span style="color: #0066CC;">String</span> =<span style="color: #ff0000;">&quot;&quot;</span>;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> AuthenticationModel<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			state = LOGGED_OUT;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">/**
		 * API method to logIn
		 *
		 */</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> logIn<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>canLogIn<span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
				<span style="color: #000000; font-weight: bold;">var</span> user:UserVO = <span style="color: #000000; font-weight: bold;">new</span> UserVO<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
				user.<span style="color: #0066CC;">password</span> = _password;
				user.<span style="color: #006600;">userName</span> = _userName;
&nbsp;
				<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">le</span>:LogInEvent = <span style="color: #000000; font-weight: bold;">new</span> LogInEvent<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
				<span style="color: #0066CC;">le</span>.<span style="color: #0066CC;">data</span> = user;
				<span style="color: #0066CC;">le</span>.<span style="color: #006600;">dispatch</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> logOut<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">//TODO implement logic to secure that log out can take place</span>
			userName = <span style="color: #ff0000;">&quot;&quot;</span>;
			<span style="color: #0066CC;">password</span> = <span style="color: #ff0000;">&quot;&quot;</span>;
			<span style="color: #000000; font-weight: bold;">new</span> LogOutEvent<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">dispatch</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> state<span style="color: #66cc66;">&#40;</span>value:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">//TODO implement logic for setting state</span>
			_currentState = value;
			<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>value == LOGGING_IN<span style="color: #66cc66;">&#41;</span>
				<span style="color: #0066CC;">status</span> = <span style="color: #ff0000;">&quot;Logging In&quot;</span>;
			<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>value == LOGGED_IN<span style="color: #66cc66;">&#41;</span>
				<span style="color: #0066CC;">status</span> = <span style="color: #ff0000;">&quot;Logged In&quot;</span>;
			<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>value == LOGGING_OUT<span style="color: #66cc66;">&#41;</span>
				<span style="color: #0066CC;">status</span> = <span style="color: #ff0000;">&quot;Logging Out&quot;</span>;
			<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>value == LOGGED_OUT<span style="color: #66cc66;">&#41;</span>
				<span style="color: #0066CC;">status</span> = <span style="color: #ff0000;">&quot;Logged Out&quot;</span>;
&nbsp;
		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> state<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> _currentState;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> userName<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> _userName;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> userName<span style="color: #66cc66;">&#40;</span>value:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			_userName = value;
			validateUserName<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> <span style="color: #0066CC;">password</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> _password;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> <span style="color: #0066CC;">password</span><span style="color: #66cc66;">&#40;</span>value:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			_password = value;
			validatePassword<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">/**
		 * INTERNAL validation methods
		 *
		 */</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> validateUserName<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">//TODO implement validation logic and rules</span>
			_userNameIsValid = _userName.<span style="color: #0066CC;">length</span> <span style="color: #66cc66;">&amp;</span>gt; <span style="color: #cc66cc;">3</span>;
			validateLogIn<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> validatePassword<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">//TODO implement validation login and rules</span>
			_passwordIsValid = _password.<span style="color: #0066CC;">length</span> <span style="color: #66cc66;">&amp;</span>gt; <span style="color: #cc66cc;">3</span>;
			validateLogIn<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> validateLogIn<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			canLogIn = _passwordIsValid <span style="color: #66cc66;">&amp;</span>amp;<span style="color: #66cc66;">&amp;</span>amp; _userNameIsValid;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Looking at the above we can see that our Authentication Model actually has an API (logIn and logOut) that reflects the use cases we want our Presentation Model to present. These two methods are now handled accordingly to the state of the Model. If, in this case, the password and user name checks out, a CairngormEvent is dispatched to be taken care of by the controller -&gt; command structure. Besides this API you should see that the validation, and enabling of the ability to login is handled by the Model. This is handles by letting the View set the user name and password data each time it changes in the view. - thus making the actual view very thin in terms of knowledge.</p>
<p>I&#8217;m still presenting the state of the model as a string (though arguable the state is now composed by multiple data variables) but in other and more complex Presentation Models could easily have a real state (machine) pattern implementation.</p>
<p>Now that we have glimpsed at the new Presentation Model implementation, lets see how the actual View has been changed to correspond to this. In this example I have chosen the LogInPanel as it uses the AuthenticationModel just described. You should <a href="http://www.asgerlaursen.com/wp-content/uploads/2008/18/ex3/" >check out the running example 3</a> to see the full source.</p>
<p><strong>LogInPanel View</strong></p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p42code38'); return false;">View Code</a> MXML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p4238"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
</pre></td><td class="code" id="p42code38"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Panel</span> xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> horizontalAlign=<span style="color: #ff0000;">&quot;center&quot;</span> verticalAlign=<span style="color: #ff0000;">&quot;middle&quot;</span> </span>
<span style="color: #000000;">    layout=<span style="color: #ff0000;">&quot;vertical&quot;</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> height=<span style="color: #ff0000;">&quot;100%&quot;</span></span>
<span style="color: #000000;">    currentState=<span style="color: #ff0000;">&quot;{authPM.state}&quot;</span> title=<span style="color: #ff0000;">&quot;{authPM.status}&quot;</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #339933;">&lt;mx:Script&gt;</span>
<span style="color: #339933;">    &lt;![CDATA[</span>
<span style="color: #339933;">        import model.presentation.AuthenticationModel;</span>
&nbsp;
<span style="color: #339933;">        [Bindable]</span>
<span style="color: #339933;">        public var authPM:AuthenticationModel;</span>
&nbsp;
<span style="color: #339933;">    ]]&gt;</span>
<span style="color: #339933;">&lt;/mx:Script&gt;</span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:states</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:State</span> name=<span style="color: #ff0000;">&quot;loggedOut&quot;</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:AddChild</span><span style="color: #7400FF;">&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:VBox</span><span style="color: #7400FF;">&gt;</span></span>
                 <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Form</span><span style="color: #7400FF;">&gt;</span></span>
                    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:FormItem</span> label=<span style="color: #ff0000;">&quot;User Name:&quot;</span><span style="color: #7400FF;">&gt;</span></span>   
                        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:TextInput</span> id=<span style="color: #ff0000;">&quot;userName&quot;</span> change=<span style="color: #ff0000;">&quot;authPM.userName = userName.text&quot;</span> text=<span style="color: #ff0000;">&quot;{authPM.userName}&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:FormItem</span><span style="color: #7400FF;">&gt;</span></span>
                    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:FormItem</span> label=<span style="color: #ff0000;">&quot;Password&quot;</span><span style="color: #7400FF;">&gt;</span></span>
                        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:TextInput</span> id=<span style="color: #ff0000;">&quot;password&quot;</span> displayAsPassword=<span style="color: #ff0000;">&quot;true&quot;</span> change=<span style="color: #ff0000;">&quot;authPM.password = password.text&quot;</span> text=<span style="color: #ff0000;">&quot;{authPM.password}&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:FormItem</span><span style="color: #7400FF;">&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Form</span><span style="color: #7400FF;">&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:VBox</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:AddChild</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:AddChild</span><span style="color: #7400FF;">&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:ControlBar</span><span style="color: #7400FF;">&gt;</span></span>
                    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Button</span> label=<span style="color: #ff0000;">&quot;Log In&quot;</span> enabled=<span style="color: #ff0000;">&quot;{authPM.canLogIn}&quot;</span> click=<span style="color: #ff0000;">&quot;authPM.logIn()&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:ControlBar</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:AddChild</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:State</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:State</span> name=<span style="color: #ff0000;">&quot;loggingIn&quot;</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:AddChild</span><span style="color: #7400FF;">&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Label</span> text=<span style="color: #ff0000;">&quot;Logging in, please wait...&quot;</span> fontSize=<span style="color: #ff0000;">&quot;22&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:AddChild</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:State</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:State</span> name=<span style="color: #ff0000;">&quot;loggedIn&quot;</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:AddChild</span><span style="color: #7400FF;">&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:VBox</span><span style="color: #7400FF;">&gt;</span></span>
                    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Label</span> text=<span style="color: #ff0000;">&quot;You are logged in as {authPM.userName}&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:VBox</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:AddChild</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:AddChild</span><span style="color: #7400FF;">&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:ControlBar</span><span style="color: #7400FF;">&gt;</span></span>
                    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Button</span> label=<span style="color: #ff0000;">&quot;Log Out&quot;</span> click=<span style="color: #ff0000;">&quot;authPM.logOut()&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:ControlBar</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:AddChild</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:State</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:State</span> name=<span style="color: #ff0000;">&quot;loggingOut&quot;</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:AddChild</span><span style="color: #7400FF;">&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Label</span> text=<span style="color: #ff0000;">&quot;Logging out, please wait...&quot;</span> fontSize=<span style="color: #ff0000;">&quot;22&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:AddChild</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:State</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:states</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Panel</span><span style="color: #7400FF;">&gt;</span></span></pre></td></tr></table></div>

<p>As you can see; the View is much cleaner and stripped from most of the logic. After the reference to the AuthenticationModel gets injected the LogInPanel binds all its View Controls to state and properties of the Model. The <em>change</em> event fired from the TextInput fields is defined to set the property on the Model, and the buttons&#8217; <em>click</em> events are triggering parts of the Models interface.</p>
<p>With the thinning of the View our AggregatedView also get stripped down, actually to only having the responsibility to inject the dependencies (and in our case to lay out the components).</p>
<p>You should take a look at <a href="http://www.asgerlaursen.com/wp-content/uploads/2008/18/ex3/" >the source in example 3.</a></p>
<p>Another thing worth noticing is that in my example, I have two kinds of Presentation Models; one being strictly the Abstracted View logic, and nothing more (Authentication Model) and the other being both an Abstracted View Model but also a Domain related Representation (Economy Model as it is directly associated and defined by states in Domain Model objects). I call them the Self Sustained Presentation Model, and the Domain Sustained Presentation Model respectively. We could even go further and claim that the Application Model in the Examples is a Specialized Presentation Model as it&#8217;s presentation ground remains on other Presentation Models, hence the specialization.</p>
<p><strong>Overview</strong><br />
So lets look at how the structure is.<br />
In the below UML diagram I have sketched out how the concepts and patterns collaborate in example 3. I have not named the classes as they are named in the Cyber Wallet domain, but as their role in the architecture. As in the diagram in example 2, I have included the Business package of the architecture, thugh it is not implemented and discussed in the examples. In this state of the architecture a new &#8220;player&#8221; has entered the field; the responder. In stead of having the delegate class or the command handling the respons from the business layer, an actual responder is given the responsability of handling and massaging data. So in terms of the GRASP (-patterns) the coherent responsability of handling business respons, is moved from either the command which only executes in regard to its concrete implementation and the delegate only delegates the business tier, to a responder (in the diagram the Responder and the Delegate should also be understood as conceret implementations of the concepts respectively).</p>
<p><img class="alignnone" title="Cairngorm Setup Step 3" src="http://www.asgerlaursen.com/wp-content/uploads/2008/12/cairngormSetupStep3.png" alt="" width="862" height="741" /></p>
<p><strong>Retrospective</strong><br />
The Presentation Model provided a good solution to my two mentioned challenges. The View got thinner, the AggragatedView got cleaned out, and the Representation Models matured and grew up and took on more coherent responsibility. And this is about where I am to day. I&#8217;m constantly looking at new patterns, thinking about ways to improve here and there. There is still many places where I haven&#8217;t been with Cairngorm yet, so I&#8217;m sure that my journey is far from over. - I hope it&#8217;s not. I hope there is many miles left to be wandered, as sometimes it&#8217;s not what you ended up with that matters the most, but the way you got it! It has been great walking down memory lane, and fun to see how perspective and understanding changes over time.</p>
<p>Looking a head I&#8217;m very excited to see Gumbo/Flex 4 evolve. As I write this, a lot of the specs for the new Flex 4 component architecture has been released. This new separation between presentation logic and graphical View is very interesting and I am really looking forward to how this will be adding to the next step in my Cairngom journey, and the way I work together with the great designers in our team.</p>
<p>My first Cairngorm Confession is over; a journey looking back at the last couple of years in my life with Cairngorm and Flex. It has been great to stroll down memory lane. I hope you enjoyed it as well.<br />
Again, I want to re-iterate that the examples isn&#8217;t created to show best practices in Flex, maybe not even in Cairngorm, but to support my rambling about the concepts I got to know and evolve around in my journey. I might find the time to clean the examples up, and make them nice and consistent, but for now I hope you&#8217;ll live without and are able to derive the essence of my points.</p>
]]></content:encoded>
			<wfw:commentRss>http://asgerlaursen.com/2008/12/28/cairngorm-confessions-the-journey/feed/</wfw:commentRss>
		</item>
		<item>
		<title>ActionScript, RIA and DSL&#8217;s part 1</title>
		<link>http://asgerlaursen.com/2008/12/14/ria-and-dsl-part-1/</link>
		<comments>http://asgerlaursen.com/2008/12/14/ria-and-dsl-part-1/#comments</comments>
		<pubDate>Sun, 14 Dec 2008 16:50:18 +0000</pubDate>
		<dc:creator>Asger</dc:creator>
		
		<category><![CDATA[ActionScript]]></category>

		<category><![CDATA[Business Domain]]></category>

		<category><![CDATA[DSL]]></category>

		<category><![CDATA[Use Cases]]></category>

		<category><![CDATA[API]]></category>

		<category><![CDATA[Framework]]></category>

		<category><![CDATA[Use Case]]></category>

		<guid isPermaLink="false">http://riablog.dk/?p=6</guid>
		<description><![CDATA[Introduction
For some time now, I have been wanting to take a closer look at Domain Specific Languages (DSL) and their whereabout in Rich Internet Applications. Actually I got interested in the subject at the JAOO conference earlier this year.
Here I got the chance to participate in a full days tutorial in DSL&#8217;s held by Martin [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Introduction</strong><br />
For some time now, I have been wanting to take a closer look at Domain Specific Languages (DSL) and their whereabout in Rich Internet Applications. Actually I got interested in the subject at the JAOO conference earlier this year.<br />
Here I got the chance to participate in a full days tutorial in DSL&#8217;s held by <a href="http://martinfowler.com/" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://martinfowler.com/');">Martin Fowler</a> and <a href="http://nealford.com/" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://nealford.com/');">Neal Ford </a> from <a href="http://www.thoughtworks.com/" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://www.thoughtworks.com/');">Thought Works</a>. The tutorial took a deep dive into the general definition of a DSL and looked at the various ways to build and provide DSL&#8217;s domain experts. Later at the JAOO I had the great pleasure of being at <a href="http://www.jamesward.com/blog/" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://www.jamesward.com/blog/');">James Wards</a> session on RIA with Flex and AIR. In this session</p>
<p>James demoed a use case related to the insurance domain. The use case evolved around how to file a car crash with your insurance company. The application showed how an applicant would go about describing the car crash by placing his own car and other implicated cars in an intersection, in a graphical environment.<br />
This depicting of a business case combined with my newly awakening in the world of DSL&#8217;s got me thinking about the way many of us use RIA as a way to communicate a limited business domain trough a rich interface.<br />
As I realize this subject might take some time for me to get my head around, therefor I have decided to make it a series. In this first part I&#8217;ll try to get around what (I think) a DSL is, and how you could build a internal DSL in ActionScript.</p>
<p><strong>What&#8217;s an DSL</strong><br />
The general definition is that an DSL is a language which is specific to a certain problem domain. As opposed to General Purpose Language,  a DSL or &#8220;special purpose language&#8221; as some might call them, is constraint to provide meaning to the business domain and nothing more. It is by default defined to be a Computer Programming Language with limited expressiveness. The wikipedia also includes &#8220;visual diagramming language&#8221; as part of the definition. So in broad terms a way to communicate a domain to/with a computer.</p>
<p>To put this into a little perspective (though I just stated that an DSL IS in some way related to a Computer) I like to think of a DSL, or at least the way a language is limited to a domain, as the way to order a coffee at Starbucks.<br />
If you are not familiar with the Starbucks jargon, you should <a href="http://www.wikihow.com/Order-at-Starbucks" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://www.wikihow.com/Order-at-Starbucks');">check out this wiki</a> explaining how to order by using the Starbucks &#8220;DLS&#8221;. For instance the order: <em>I&#8217;ll have a &#8216;For Here&#8217;, Grande, Non-Fat, No Water, 180 Degrees, Tazo® Chai Tea Latte </em>is an example of an order at Starbucks. Further; this sentence only makes sense to the Starbucks business domain, it has a limited expressiveness and the syntax is human readable, though simplified.</p>
<p>This is of cause a simplification of the DSL explanation (and again, the Starbucks jargon, is just a jargon or &#8220;slang&#8221; vocabulary), but it gives a relational mapping from our world to the way we need to think of DSL in terms of a domain specific computer language.<br />
Besides the above points and some more specific rules of thumb (like a DSL never should have touring completeness etc.) it is hard to set exact boundaries for a DSL; domains are different and the need for expressiveness or the ability to limit scope varies.</p>
<p><strong>Why even bother</strong><br />
Before we walk further down the DSL road I think it is in good order to motivate why one would even go about spending time and effort on this subject. I see a close connection between Rich Internet Applications and the way we can use DSL as part of solving a problem. We deal with domain users and domain experts on a daily basis, as we both have to capture what the business domain is all about, and create the interface that make the user collaborate with this domain. A lot of the applications we build, is created with an expressive and rich interface. - Interfaces which, in my point of view, can be exactly that visual abstraction on top of a problem domain, the wikipedia calls: <em>&#8220;visual diagramming language&#8221;. </em>I&#8217;ll in the following try to showcase what I think a DSL is, and how it is implemented internally and externally (in code and/or graphically).</p>
<p>In the attempt to get my own (and hopefully your) head around how some thoughts about DLS&#8217;s could benefit the way we think about creating (Rich Internet) Applications, we need a little &#8220;case&#8221; project&#8221;  This &#8220;case&#8221; will be the context to which I can refer troughout this post (and in later parts). I&#8217;ll try to outline a VERY simplified business domain (so please don&#8217;t ask to many clarifying quesitons about this given scenario, I promise I&#8217;ll return in a later part with a more &#8220;real world&#8221; piece of meet).</p>
<p><strong>Our point of entrance case</strong><br />
So lets say we are building an application which is to be used by a big chain of bakeries to control the pipeline of bread being baked every day. The bakers will be using the application to look up recipes, provided trough a graphical step by step user interface, making it easy for even novice bakers to follow along and bake bread.</p>
<p>Our domain clearly evolves around the bakery-domain, where we need to focus especially on the Recipe Model as that is what our application will do a lot of work with. When we start our work with the domain expert; the experienced chief baker. From him we learn that the bakery chain already have a lot of recipes laying around.<br />
All these should be &#8220;programmed/stored&#8221; in to our system (for instance into a database) at start up, so that the application from day one will be able to show all the recipes used today. Besides that; every day, new and exotic recipes are discovered world wide, and the chief baker, wants an easy way to provide new recipes to the baker system. These new recipes could be found in a news paper or book, send to the chief on a mail,  or sometimes the chief baker even receives recipes on a bar napkins (from a fellow bakers stroked by  moments of bread-creativity when drinking heavily).</p>
<p>So what options do we have for providing a means for the chief baker to get all the recipes into the system. One option would be to create a form, maybe even just one big text field for the chief to write a recipe into, exactly as it would read in the book, paper or mail. But this solution isn&#8217;t good (for various reasons) as we need to remember; the application is suppose to guide the bakers trough the recipe thus having to break the recipe up in to coherent chunks. This will be impossible to say the least, to do with one big string of text. So another option would be to create multiple text fields each representing a step in the recipe, for the chief to fill in. This way the chief as the domain expert would have the ability to chunk the recipe up into coherent steps which would make sense when baking the bread.</p>
<p>Though this solution seams better at first, I think there is a lot to be cautious about in an approach like this. First of all; chunking the recipe up and gathering it up by a series of fields do not give us much more about the recipe besides the chunks them selves. If we want to use the data in the recipes to anything besides just showing the text representing a step, we would have a hard time doing so. In an example, say we wanted to show the process of a baking step in a recipe, by graphically counting down the minutes left the dough had to be in the oven. - how and here would get these informations if they were hidden in some chunk of text saying &#8220;now bake the dough for 25 minutes&#8221;. We might also want to search for recipes containing certain amounts of certain ingredients; a thing which also would be hard to do, with recipes just saved as chunks of strings.</p>
<p>&#8220;So, lets make an actual form, with an ingredient list, an ingredient-mixing step, a rising step, a baking step etc, so that we know more about the actual data being submitted&#8221;, I see the point in this approach, but I still think we might come in short by this approach. Recipes can be complex, and some might contain multiple baking steps, no rising step, etc. thus making it hard to limit the chief to a &#8220;one form fits all&#8221; approach. We could continue making the form more sophisticated and so on, but my point is of cause, that we should/could also consider thinking in terms of a Domain Specific Language; a language limited to the baker and recipe domain, with a limited expressiveness and with concepts familiar to the chief baker.</p>
<p>I&#8217;ll leave our bakery for now, the above case was primarily to get us into a solution-thinking-state-of-mind which we can leverage when going trough the following. By not giving my idea (not yet at least) of a solution to how we should solve the bakery application, I hope your own creativity will have more room for thinking of ways to create a fitting solution. - hopefully a solution which will be inspired by the DSL-road trip we are about to take.<br />
I&#8217;ll now return to a more concrete talk about what a DSL is, the different types and how they can be implemented.</p>
<p><strong>Different types of DSL&#8217;s</strong><br />
Generally DSL&#8217;s are defined in two main categories: internal DSL&#8217;s and external DSL&#8217;s. When talking about the types of DSL&#8217;s it is important to understand who the target audience is. Internal DSL&#8217;s are in my opinion more targeted technology persons (what an exact and concise definition <img src='http://asgerlaursen.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> ). What I mean by this, as you will read in a moment, is that internal DSL&#8217;s always will be bound to some sort of development environment element(s) (this being a hosting general purpose language, an IDE or editor, a general purpose language compiler and limited syntax). Therefor I think internal DSL&#8217;s are in broad mostly relevant to people knowing their way around a computer, but not necessarily a developer . In comparison to internal, the external DSL is not in a host language, thus being without the constraints related to an internal DSL. An external DSL, is in my opinion very interesting in regard to end-users and non technical people with expertise in a domain. The external DSL category is also where  the &#8220;visual diagramming languages&#8221; fits in.</p>
<p><strong>Internal DSL</strong><br />
In short an internal DSL is a language written in a &#8220;host&#8221; language. By host you should understand the General Purpose Language being used to write an &#8220;abstraction&#8221; or DSL in. As an example it would mean an DSL written in ActionScript to provide a higher programming abstraction trough a specific set of domain &#8220;objects&#8221; (objects as in domain related terms and model interpretations)  and limited syntax. The syntax limiting is always limited to the ways to go about in the host language. As you actually is writing ActionScript you are not able to do any new and fancy formatting, as it is to be interpreted by the same compiler as normal ActionScript. Though, often it is possible to use little tweaks to hide the underlying host language, or <em>noise</em>, more or less.  As an example the following snippet our Starbucks order from above, written in an Startbucks DSL, written i ActionScript:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p6code48'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p648"><td class="code" id="p6code48"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> latte:Coffee = <span style="color: #000000; font-weight: bold;">new</span> Coffee<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
.<span style="color: #0066CC;">size</span> = CoffeeSize.<span style="color: #006600;">GRANDE</span>
.<span style="color: #006600;">where</span> = Consumption.<span style="color: #006600;">FOR_HERE</span>
.<span style="color: #006600;">fat</span> = FatContent.<span style="color: #006600;">NON_FAT</span>
.<span style="color: #006600;">water</span> = Water.<span style="color: #006600;">NO_WATER</span>
.<span style="color: #006600;">temperature</span> = <span style="color: #cc66cc;">180</span>
.<span style="color: #0066CC;">type</span> = CoffeeType.<span style="color: #006600;">TAZO_CHAI_TEA_LATTE</span>;</pre></td></tr></table></div>

<p>What you should notice is the use of multiple lines, all of them starting with a &#8220;.&#8221;. This way of chain the syntax together, and not breaking any compiler/language rules while still providing a better readability is called Method Chaining&#8221;. Method Chaining can be part of the way of achieving what is know as a Fluent Interface&#8221;. Fluent Interfaces is the concept of treating lines of code as sentences, like we just did with the method chaining above. I cant help thinking about how frameworks and API&#8217;s in general can benefit from the thoughts related to DSL&#8217;s and fluent interfaces. A great example of DSL (if you would argue that testing is a domain) and fluent interfaces is Test Driven Development with JUnit, Hamcrest and JMock, where your are able to create logical, readable constructs when writing your tests, by using method chaining and subsequent calls. See the example below:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p6code49'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p649"><td class="code" id="p6code49"><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> MyTestCase <span style="color: #009900;">&#123;</span>
    ...
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> testSomething<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        ...
&nbsp;
        <span style="color: #006633;">context</span>.<span style="color: #006633;">checking</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Expectations<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#123;</span>
            oneOf <span style="color: #009900;">&#40;</span>logger<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">error</span><span style="color: #009900;">&#40;</span>with<span style="color: #009900;">&#40;</span>aStringStartingWith<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;FATAL&quot;</span><span style="color: #009900;">&#41;</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><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        ...
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>In the above we see how we can construct a human-readable string (at least a programmer-readable string) by using the syntax and method naming around the JMock and testing domain.</p>
<p>In regard to the Fluent Interface and Method Chaining there is a little advantage in ActionScript in our ability to write properties as getter/setter methods. This can help us remove a little more noise from our DSL. In practical terms we are able to change the &#8220;( )&#8221; with a &#8221; = &#8221; which is a more known operator for non developers; assigning a value on the right side to something on the left side. - like we did it in our Coffee example above. The trick in using method chaining and getter/setter, as you properly have figured out, is to let each setter return the containing object itself:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p6code50'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p650"><td class="code" id="p6code50"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Coffee
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Coffee<span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">//...</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> <span style="color: #0066CC;">size</span><span style="color: #66cc66;">&#40;</span>value:CoffeeSize<span style="color: #66cc66;">&#41;</span>:Coffee
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">//...</span>
			<span style="color: #b1b100;">return</span> <span style="color: #0066CC;">this</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> where<span style="color: #66cc66;">&#40;</span>value:Cosumption<span style="color: #66cc66;">&#41;</span>:Coffee
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">//...</span>
			<span style="color: #b1b100;">return</span> <span style="color: #0066CC;">this</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p><strong>The Bakery internal DSL</strong><br />
We could argue that we should create an internal recipe DSL to our chief baker. This would of cause not be the best thing to do, as our dear chief baker might not be very familiar with computers when it comes to tasks outside the &#8220;normal use&#8221;-boundaries. But on the other side, that would just mean that we would have to be even more focused on providing a domain language to the chief that &#8220;feels at home&#8221; and hides away constraints and noise in our host language.<br />
To remove this &#8220;host language noise&#8221; we will of cause use what ever tweak we can in our language, to make it more fluent.</p>
<p>The creation of a recipe, in our Bakery DSL could look like something like this:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p6code51'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p651"><td class="code" id="p6code51"><pre class="actionscript" style="font-family:monospace;"> <span style="color: #000000; font-weight: bold;">var</span> r:Recipe = <span style="color: #000000; font-weight: bold;">new</span> Recipe
 <span style="color: #66cc66;">&#40;</span>
&nbsp;
	<span style="color: #0066CC;">add</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">25</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">grams</span>.<span style="color: #006600;">of</span>.<span style="color: #006600;">flour</span>,
	<span style="color: #0066CC;">add</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">oz</span>.<span style="color: #006600;">of</span>.<span style="color: #006600;">water</span>,
	mix<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>,
	<span style="color: #0066CC;">add</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">kilos</span>.<span style="color: #006600;">of</span>.<span style="color: #006600;">sugar</span>,
	mix<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>,
	rise<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">hours</span>,
	bake<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">30</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">minutes</span>.<span style="color: #006600;">at</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">200</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">celcius</span>
&nbsp;
<span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p>As you can see we try to make it very sentence like, by constructing expressions that look as close as possible to the way we actually describe a recipe in the real world; <em>&#8220;Add 25 grams of flour&#8221;</em>. The way I have achieved the above syntax in a language like ActionScript is by using the Proxy class in AS3, a factory, and a set of package methods.<br />
I&#8217;ll in the following show how it is implemeted.</p>
<p>Here is my Bakery App project:</p>
<p><img class="alignnone" title="Project Navigator Panel" src="http://asgerlaursen.com/wp-content/uploads/2008/12/navigatorPanelForBakeryApp1.png" alt="" width="254" height="350" /></p>
<p><strong>Recipe Class</strong><br />
The Recipe class, which constructor takes an unspecified list of ingredients and actions in the order they should be executed. This is done by using the &#8220;&#8230;&#8221; syntax in AS3. This way the handling of the various elements and steps constituting the recipe can be handled generic. As mentioned above one problem with static forms could be, that some recipes have multiple baking steps, and others none. By pushing a list of n&#8217; in the constructor we are not locked to any order, or any special sequence. The implementation of what to do with the elements when they are received in the constructor is not of interest here, as much as HOW we go about and create the elements we want in a recipe.</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p6code52'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p652"><td class="code" id="p6code52"><pre class="actionscript" style="font-family:monospace;">package model
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Recipe
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Recipe<span style="color: #66cc66;">&#40;</span>...<span style="color: #006600;">args</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">//...</span>
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p><strong>The Ingredient</strong><br />
Inside the constructor call of the recipe, we make use of a set of statements which starts with a &#8220;key word&#8221; related to an action in our domain. The first line, which will look closer at adds a new ingredient to the recipe:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p6code53'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p653"><td class="code" id="p6code53"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">add</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">25</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">grams</span>.<span style="color: #006600;">of</span>.<span style="color: #006600;">flour</span></pre></td></tr></table></div>

<p>What is actually created in this sentence is new instance of an ingredient object with 25 as the amount, grams as the measuring unit and flour as the name of the ingredient. The implementation of the ingredient class is shown below here. It is in it self not very interesting, but the interesting part is how we remove the noise of object creation from the language we want to provide, and make the syntax intuitive:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p6code54'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p654"><td class="code" id="p6code54"><pre class="actionscript" style="font-family:monospace;">package model
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Ingredient
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _amount:<span style="color: #0066CC;">Number</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _measureUnit:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">_name</span>:<span style="color: #0066CC;">String</span>;
		<span style="color: #808080; font-style: italic;">//...</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Ingredient<span style="color: #66cc66;">&#40;</span>amount:<span style="color: #0066CC;">Number</span>,measureUnit:<span style="color: #0066CC;">String</span>,<span style="color: #0066CC;">name</span>:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			_amount = amount;
			_measureUnit = measureUnit;
			<span style="color: #0066CC;">_name</span> = <span style="color: #0066CC;">name</span>;
&nbsp;
			<span style="color: #808080; font-style: italic;">//...</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">//...</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p><strong>Package Method</strong><br />
So now we know how we should end up; with an ingredient object, with a measuring unit, an amount and an ingredient name. We start this process by calling &#8220;add&#8221;.<br />
The add &#8220;key word&#8221; which is actually just a method declared in an ActionScript file in a package, can be used, everywhere as long as it is imported to the current file you are working in. It is like other methods like &#8220;navigateToURL&#8221; etc. already in the AS3 API. What I like about doing it this way, in stead of having a local add method in the containing class, is the separation. As you can see in the overview of the project, all the add, bake, rise, mix methods is in their own package.</p>
<p>This makes it easy to control what domain actions reside, and you don&#8217;t have to clutter the Recipe class or the class where you want to use the DSL by implementing all these methods there. So to say we delegate the responsibility of &#8220;catching the domain action&#8221; out to a separate method, instead of having this in a class. This also makes it easier to maintain if the implementation of certain method names or &#8220;domain actions&#8221; changes. And lastly, it gives a great overview, of the domain actions. - also in terms of collaboration with the domain experts, as the extraction and abstraction is very human readable.<br />
The actual implementation of the &#8220;add&#8221; method (and most of the others for that matter) is a further delegation of control, to an appropriate factory class. Here is the implementation of the &#8220;add&#8221;:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p6code55'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p655"><td class="code" id="p6code55"><pre class="actionscript" style="font-family:monospace;">package actions
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> util.<span style="color: #006600;">IngredientFactory</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">add</span><span style="color: #66cc66;">&#40;</span>amount:<span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#41;</span>:IngredientFactory
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> IngredientFactory<span style="color: #66cc66;">&#40;</span>amount<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p><strong>The Factory </strong><br />
As shown above, the &#8220;add&#8221; method delegates the amount passed in, to an &#8220;IngredienFactory&#8221; class. If we continue to look at our sentence under investigation, we see that the following is a chained expression of the measuring unit, and the name of the ingredient.<br />
<del>add(25)</del>.grams.of.flour<br />
If we look inside our &#8220;IngredientFactory&#8221; we see that this is implemented by extending the AS3 Proxy, thus making our &#8220;IngredientFactory&#8221; dynamic, and open for any type of property call (gram, grams, kilo, kilos, oz, pieces, piece, &#8230;)</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p6code56'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p656"><td class="code" id="p6code56"><pre class="actionscript" style="font-family:monospace;">package util
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">Proxy</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">flash_proxy</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> model.<span style="color: #006600;">Ingredient</span>;
&nbsp;
	<span style="color: #0066CC;">dynamic</span> <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> IngredientFactory <span style="color: #0066CC;">extends</span> Proxy
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _measureUnit:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _amount:<span style="color: #0066CC;">Number</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _addingName:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">false</span>;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> IngredientFactory<span style="color: #66cc66;">&#40;</span>amount:<span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			_amount = amount;
		<span style="color: #66cc66;">&#125;</span>
		override flash_proxy <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">getProperty</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">name</span>:<span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #66cc66;">*</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> result:<span style="color: #66cc66;">*</span>;
&nbsp;
			<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>_addingName<span style="color: #66cc66;">&#41;</span>
				result = <span style="color: #000000; font-weight: bold;">new</span> Ingredient<span style="color: #66cc66;">&#40;</span>_amount,_measureUnit,<span style="color: #0066CC;">name</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #b1b100;">else</span>
			<span style="color: #66cc66;">&#123;</span>
		 		_measureUnit = <span style="color: #0066CC;">name</span>;
				result = <span style="color: #0066CC;">this</span>;
			<span style="color: #66cc66;">&#125;</span>
		 	<span style="color: #b1b100;">return</span> result;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> of<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:IngredientFactory
		<span style="color: #66cc66;">&#123;</span>
			_addingName = <span style="color: #000000; font-weight: bold;">true</span>;
			<span style="color: #b1b100;">return</span> <span style="color: #0066CC;">this</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>As you can see I have made the &#8220;getting&#8221; of &#8220;of&#8221; the trigger, that assembles the amount, the measuring unit, and the name of the ingredient, and returns a new instance of an ingredient, with these arguments in the constructor. The is of cause based on the concordance that an &#8220;ingredient sentence&#8221; is always composed like:</p>
<p>&lt;code&gt;measuringUnit.of.ingredientName&lt;/code&gt;</p>
<p><strong> </strong>This concordance should of cause be derived from the domain (hence the domain experts). In this example I&#8217;ll not go deeper into the domain, but you could try to think about how you would create the ability to say something like &#8220;add(2).eggs&#8221; where there is no measure unit (or it is at least implicit in the sentence) and no use of the &#8220;of&#8221; keyword.</p>
<p>Besides the &#8220;add&#8221; method, I have in my example created methods like &#8220;mix&#8221;, &#8220;bake&#8221; and &#8220;rise&#8221;, and there could be many more. In our bakery domain they make perfect sense in the construction of a recipe. And we would now know when to tell the bakers to mix ingredients, when and how long to rise, and at what temperature the bread should be baked.</p>
<p>So to sum up the implementation pattern used;</p>
<ol>
<li>we subsequent the steps and ingredients as arguments to the constructor</li>
<li>we create domain actions as package methods</li>
<li>we delegate the creation of domain objects/concepts to a dynamic factory</li>
</ol>
<p>As mentioned this is example is very staged and the point was not to show how to develop a bakery application, but to show how to abstract an API or Domain concepts inside a programming language, into a higher level DSL.</p>
<p><strong>Outro on part 1</strong><br />
Pheew, boy was that a lot of words. I&#8217;m glad I decided to make this a series, otherwise I would never get to close up this blog post <img src='http://asgerlaursen.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /><br />
I hope you have gotten a glimpse of what a DSL is in general, and what a DSL is in terms of an &#8220;internal DSL&#8221;. I also hope you have gotten the idea of how you could create such an internal DSL in ActionScript by using some of the great dynamic possibilities we have at hand.<br />
In terms of internal DSL&#8217;s AS1/2 was actually even more dynamic with its implicit declarations and weak typing. These qualities (though people often do not look at them as qualities) is some of the things people value in Ruby, which is gaining momentum these days, as a language for writing internal DSL&#8217;s.<br />
In the next part on the subject I&#8217;ll be taking closer a look at external DSL&#8217;s and how we with Rich interfaces can create visual DSL&#8217;s to use for the domain experts.</p>
]]></content:encoded>
			<wfw:commentRss>http://asgerlaursen.com/2008/12/14/ria-and-dsl-part-1/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Through the mouth the heart speaks</title>
		<link>http://asgerlaursen.com/2008/12/09/through-the-mouth-the-heart-speaks/</link>
		<comments>http://asgerlaursen.com/2008/12/09/through-the-mouth-the-heart-speaks/#comments</comments>
		<pubDate>Mon, 08 Dec 2008 23:24:42 +0000</pubDate>
		<dc:creator>Asger</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://riablog.dk/?p=10</guid>
		<description><![CDATA[I guess the title is very much how I hope this blog will turn out. For some time now (years actually) I have wanted to get my personal blog going. Even though I have tried setting up wordpress or other blog-featuring CMS&#8217;, I have never managed to get passed that initial &#8220;Hello World&#8221; post. - [...]]]></description>
			<content:encoded><![CDATA[<p>I guess the title is very much how I hope this blog will turn out. For some time now (years actually) I have wanted to get my personal blog going. Even though I have tried setting up wordpress or other blog-featuring CMS&#8217;, I have never managed to get passed that initial &#8220;Hello World&#8221; post. - so here goes.</p>
<p><strong>Getting past that &#8220;hello world&#8221; post</strong><br />
I guess that my lack of bloggin is due to a great involvement in the Danish online RIA community <a href="http://www.flashforum.dk" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://www.flashforum.dk');">FlashForum</a> which I am co-managing. Besides taking a lot of my time, writing tutorials, articles and helping people out at the forum onthe community site satisfy my urge to write. But still I have decided to give the personal blog a tryout.</p>
<p><strong>Why go for more?</strong><br />
In the year passed, the need for a textual sanctuary has emerged; a place for me to geek out, and let the mouth speak what fills the heart, has been needed. So I hope this blog will give me the &#8220;lungs of the city&#8221; that I have longed for.</p>
<p>I&#8217;m looking forward to an exciting time here, on my own playground <img src='http://asgerlaursen.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://asgerlaursen.com/2008/12/09/through-the-mouth-the-heart-speaks/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

