<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Shaun Smith &#187; architecture</title>
	<atom:link href="http://shaun.boyblack.co.za/blog/tag/architecture/feed/" rel="self" type="application/rss+xml" />
	<link>http://shaun.boyblack.co.za/blog</link>
	<description>Flex, Ruby, Mongo - London, UK</description>
	<lastBuildDate>Sun, 05 Feb 2012 04:20:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>RobotLegs &#8211; RazorSharpness Through Collaboration</title>
		<link>http://shaun.boyblack.co.za/blog/2009/10/03/robotlegs-razorsharpness-through-collaboration/</link>
		<comments>http://shaun.boyblack.co.za/blog/2009/10/03/robotlegs-razorsharpness-through-collaboration/#comments</comments>
		<pubDate>Sat, 03 Oct 2009 14:17:15 +0000</pubDate>
		<dc:creator>shaun</dc:creator>
				<category><![CDATA[Robotlegs]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[collaboration]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[yagni]]></category>

		<guid isPermaLink="false">http://shaun.boyblack.co.za/blog/?p=824</guid>
		<description><![CDATA[Help make RobotLegs the cleanest, smallest, most testable, and most kick-ass framework for Flash and Flex ever built &#8211; join the discussion group: http://groups.google.com/group/robotlegs/topics Or help fill up the Robotlegs Knowledgebase: http://knowledge.robotlegs.org/]]></description>
			<content:encoded><![CDATA[<p><a href="http://groups.google.com/group/robotlegs/browse_thread/thread/68569a7c85ce4c92"><img class="alignnone size-full wp-image-825" title="Yagninator" src="http://shaun.boyblack.co.za/blog/wp-content/uploads/2009/10/Yagninator.jpg" alt="Yagninator" width="512" height="384" /></a></p>
<p>Help make RobotLegs the cleanest, smallest, most testable, and most kick-ass framework for Flash and Flex ever built &#8211; join the discussion group:</p>
<p><a title="RobotLegs AS3 Discussion Group" href="http://groups.google.com/group/robotlegs/topics">http://groups.google.com/group/robotlegs/topics</a></p>
<p>Or help fill up the Robotlegs Knowledgebase:</p>
<p><a title="Robotlegs Knowledgebase" href="http://knowledge.robotlegs.org/">http://knowledge.robotlegs.org/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://shaun.boyblack.co.za/blog/2009/10/03/robotlegs-razorsharpness-through-collaboration/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Parsley: Your Favourite Herb?</title>
		<link>http://shaun.boyblack.co.za/blog/2009/07/12/parsley-your-favourite-herb/</link>
		<comments>http://shaun.boyblack.co.za/blog/2009/07/12/parsley-your-favourite-herb/#comments</comments>
		<pubDate>Sun, 12 Jul 2009 15:05:15 +0000</pubDate>
		<dc:creator>shaun</dc:creator>
				<category><![CDATA[Banter]]></category>
		<category><![CDATA[Resources]]></category>
		<category><![CDATA[Robotlegs]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[parsley]]></category>

		<guid isPermaLink="false">http://shaun.boyblack.co.za/blog/?p=711</guid>
		<description><![CDATA[I&#8217;ve just started looking into Parsley: http://www.spicefactory.org/parsley/ First thought: version 2 is exactly what I&#8217;ve been trying to build with RobotLegs. I&#8217;ve only briefly skimmed through the manual, but it really looks promising. I have some initial concerns (the use of Static methods for example; see: http://misko.hevery.com/2008/12/15/static-methods-are-death-to-testability/), but need more time to play around properly. The forum pointed me to these two handy example projects: http://www.sitronnier.com/blog/parsley-2-basic-flex-example http://www.sitronnier.com/blog/parsley-2-basic-flash-example Find them on the forum here: http://www.spicefactory.org/forum/viewtopic.php?t=247 All the Spice: http://www.spicefactory.org/]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just started looking into Parsley:<a title="Parsley Flash/Flex Framework" href="http://www.spicefactory.org/parsley/"> http://www.spicefactory.org/parsley/</a></p>
<p>First thought: version 2 is exactly what I&#8217;ve been trying to build with <a title="RobotLegs AS3: a DI driven MVCS framework for Flash and Flex inspired by PureMVC" href="http://shaun.boyblack.co.za/blog/robotlegs-as3/">RobotLegs</a>.<span id="more-711"></span></p>
<p>I&#8217;ve only briefly skimmed through the manual, but it really looks promising. I have some initial concerns (the use of Static methods for example; see: <a title="Static Methods are Death to Testability" href="http://misko.hevery.com/2008/12/15/static-methods-are-death-to-testability/">http://misko.hevery.com/2008/12/15/static-methods-are-death-to-testability/</a>), but need more time to play around properly.</p>
<p>The <a title="Spicefactory Forum" href="http://www.spicefactory.org/forum/">forum</a> pointed me to these two handy example projects:</p>
<p><a title="Parsley 2: Basic Flex Example" href="http://www.sitronnier.com/blog/parsley-2-basic-flex-example">http://www.sitronnier.com/blog/parsley-2-basic-flex-example</a><br />
<a title="Parsley 2: Basic Flash Example" href="http://www.sitronnier.com/blog/parsley-2-basic-flash-example">http://www.sitronnier.com/blog/parsley-2-basic-flash-example</a></p>
<p>Find them on the forum here:</p>
<p><a title="Spicefactory Forum Post: 2 examples" href="http://www.spicefactory.org/forum/viewtopic.php?t=247">http://www.spicefactory.org/forum/viewtopic.php?t=247</a></p>
<p>All the Spice:</p>
<p><a title="Spicefactory" href="http://www.spicefactory.org/">http://www.spicefactory.org/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://shaun.boyblack.co.za/blog/2009/07/12/parsley-your-favourite-herb/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>RobotLegs AS3: GitHub Wiki Updated</title>
		<link>http://shaun.boyblack.co.za/blog/2009/06/23/robotlegs-as3-github-wiki-updated/</link>
		<comments>http://shaun.boyblack.co.za/blog/2009/06/23/robotlegs-as3-github-wiki-updated/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 11:51:14 +0000</pubDate>
		<dc:creator>shaun</dc:creator>
				<category><![CDATA[Robotlegs]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[dependency injection]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>

		<guid isPermaLink="false">http://shaun.boyblack.co.za/blog/?p=696</guid>
		<description><![CDATA[I&#8217;ve added a little page to the RobotLegs Wiki: RobotLegs Overview]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve added a little page to the <a title="RobotLegs AS3 Framework" href="http://shaun.boyblack.co.za/blog/robotlegs-as3/">RobotLegs</a> Wiki: <strong><a title="RobotLegs AS3 Overview" href="http://wiki.github.com/darscan/robotlegs/overview">RobotLegs Overview</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://shaun.boyblack.co.za/blog/2009/06/23/robotlegs-as3-github-wiki-updated/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RobotLegs AS3: System/Context Event Flow</title>
		<link>http://shaun.boyblack.co.za/blog/2009/05/02/robotlegs-as3-systemcontext-event-flow/</link>
		<comments>http://shaun.boyblack.co.za/blog/2009/05/02/robotlegs-as3-systemcontext-event-flow/#comments</comments>
		<pubDate>Sat, 02 May 2009 01:20:53 +0000</pubDate>
		<dc:creator>shaun</dc:creator>
				<category><![CDATA[Banter]]></category>
		<category><![CDATA[Robotlegs]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[dependency injection]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>

		<guid isPermaLink="false">http://shaun.boyblack.co.za/blog/?p=534</guid>
		<description><![CDATA[RobotLegs AS3 is a Dependency Injection Driven MVCS Framework for Flash and Flex inspired by PureMVC. Actors may be dependent on actors below them in the diagram, but should not be dependent on anything above them. Commands, Services and Proxies may dispatch system events, but should never listen for them. Mediators may both dispatch and listen for system events. So: Commands may depend on any number of Mediators, Services and Proxies, and may dispatch system events. Mediators may depend on &#8230; <a href="http://shaun.boyblack.co.za/blog/2009/05/02/robotlegs-as3-systemcontext-event-flow/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><em><a title="RobotLegs AS3 - DI Driven MVCS Framework for Flash and Flex" href="http://wiki.github.com/darscan/robotlegs">RobotLegs AS3</a> is a Dependency Injection Driven MVCS Framework for Flash and Flex inspired by <a title="PureMVC" href="http://puremvc.org/">PureMVC</a>.</em></p>
<p><img class="alignnone size-full wp-image-666" title="RobotLegs AS3 Event Flow" src="http://shaun.boyblack.co.za/blog/wp-content/uploads/2009/05/robotlegsas3_event_flow.png" alt="RobotLegs AS3 Event Flow" width="430" height="230" /></p>
<p>Actors may be dependent on actors below them in the diagram, but should not be dependent on anything above them.</p>
<p>Commands, Services and Proxies may dispatch system events, but should never listen for them.</p>
<p>Mediators may both dispatch and listen for system events.<span id="more-534"></span></p>
<p>So:</p>
<ol>
<li>Commands may depend on any number of Mediators, Services and Proxies, and may dispatch system events.</li>
<li>Mediators may depend on other Mediators, Services and or Proxies, and may dispatch and listen for system events.</li>
<li>Services may depend on Proxies, and may dispatch system events.</li>
<li>Proxies may depend on other Proxies, and may dispatch system events.</li>
</ol>
<h3>Why?</h3>
<p>Check out the PureMVC FAQ: <a title="PureMVC FAQ" href="http://puremvc.org/content/category/3/23/188/">http://puremvc.org/content/category/3/23/188/</a></p>
<h3>Prompted By:</h3>
<p>This <a href="http://shaun.boyblack.co.za/blog/2009/04/29/another-architectural-framework-but-why/comment-page-1/#comment-3473">comment</a>, thanks!</p>
<p><strong>UPDATE</strong>: I somehow completely messed up the diagram when I last updated it.. I got the direction for the Service and Proxy event flow backwards.. Doh!</p>
]]></content:encoded>
			<wfw:commentRss>http://shaun.boyblack.co.za/blog/2009/05/02/robotlegs-as3-systemcontext-event-flow/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Constructor Injection vs Setter Injection</title>
		<link>http://shaun.boyblack.co.za/blog/2009/05/01/constructor-injection-vs-setter-injection/</link>
		<comments>http://shaun.boyblack.co.za/blog/2009/05/01/constructor-injection-vs-setter-injection/#comments</comments>
		<pubDate>Fri, 01 May 2009 17:56:37 +0000</pubDate>
		<dc:creator>shaun</dc:creator>
				<category><![CDATA[Banter]]></category>
		<category><![CDATA[Robotlegs]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[dependency injection]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[smartypants-ioc]]></category>

		<guid isPermaLink="false">http://shaun.boyblack.co.za/blog/?p=512</guid>
		<description><![CDATA[Constructor injection is theoretically superior: Constructor Injection vs Setter Injection Constructor vs Setter Injection &#8211; Constructor is Better Setter injection versus constructor injection and the use of required Before I built RobotLegs I was sold on constructor injection. My prototype, however, used SmartyPants-IOC which lacked constructor injection, so I bit my lip and used setter injection. In practice I found that often, especially with framework actors, it was incredibly convenient. Effort Unless you use a code generator, constructor injection requires &#8230; <a href="http://shaun.boyblack.co.za/blog/2009/05/01/constructor-injection-vs-setter-injection/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Constructor injection is theoretically superior:</p>
<p><a href="http://misko.hevery.com/2009/02/19/constructor-injection-vs-setter-injection/">Constructor Injection vs Setter Injection</a><br />
<a href="http://www.pbell.com/index.cfm/2006/11/18/Constructor-vs-Setter-Injection-Constructor-is-Better">Constructor vs Setter Injection &#8211; Constructor is Better</a><br />
<a href="http://blog.springsource.com/2007/07/11/setter-injection-versus-constructor-injection-and-the-use-of-required/">Setter injection versus constructor injection and the use of required</a></p>
<p>Before I built <a title="RobotLegs AS3 - DI Driven MVCS Framework for Flash and Flex" href="http://shaun.boyblack.co.za/blog/2009/04/16/robotlegs-an-as3-mvcs-framework-for-flash-and-flex-applications-inspired-by-puremvc/">RobotLegs</a> I was sold on constructor injection. My prototype, however, used <a title="SmartyPants-IOC" href="http://code.google.com/p/smartypants-ioc/">SmartyPants-IOC</a> which lacked constructor injection, so I bit my lip and used setter injection. In practice I found that often, especially with framework actors, it was incredibly convenient.<span id="more-512"></span></p>
<h2>Effort</h2>
<p>Unless you use a code generator, constructor injection requires roughly 3 times the effort (more code) and is roughly 3 times more prone to human error than this form of setter injection:</p>
<pre>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> SomeMediator<br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; <span style="color: #000000;">&#91;</span>Inject<span style="color: #000000;">&#93;</span> <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> someView<span style="color: #000066; font-weight: bold;">:</span>SomeView<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; <span style="color: #000000;">&#91;</span>Inject<span style="color: #000000;">&#93;</span> <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> someProxy<span style="color: #000066; font-weight: bold;">:</span>SomeProxy<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; <span style="color: #000000;">&#91;</span>Inject<span style="color: #000000;">&#93;</span> <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> someService<span style="color: #000066; font-weight: bold;">:</span>ISomeService<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> SomeMediator<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
</pre>
<p>Constructor injection requires twice the number of declarations and an extra assignment step.</p>
<pre>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> SomeMediator<br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> someView<span style="color: #000066; font-weight: bold;">:</span>SomeView<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> someProxy<span style="color: #000066; font-weight: bold;">:</span>SomeProxy<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> someService<span style="color: #000066; font-weight: bold;">:</span>ISomeService<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> SomeMediator<span style="color: #000000;">&#40;</span> someView<span style="color: #000066; font-weight: bold;">:</span>SomeView<span style="color: #000066; font-weight: bold;">,</span> someProxy<span style="color: #000066; font-weight: bold;">:</span>SomeProxy<span style="color: #000066; font-weight: bold;">,</span> someService<span style="color: #000066; font-weight: bold;">:</span>ISomeService <span style="color: #000000;">&#41;</span><br />
&nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// Boilerplate...</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>someView = someView<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>someProxy = someProxy<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>someService = someService<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
</pre>
<h2>Forgetfulness</h2>
<p>Let&#8217;s consider what Misko deems the biggest problem with setter injection: forgetting dependencies.</p>
<p>In the case of setter injection, and in the context of the application itself (running on the <a title="RobotLegs AS3 - DI Driven MVCS Framework for Flash and Flex" href="http://shaun.boyblack.co.za/blog/2009/04/16/robotlegs-an-as3-mvcs-framework-for-flash-and-flex-applications-inspired-by-puremvc/">RobotLegs</a> framework), if we forget to set up a dependency rule, we&#8217;ll get a runtime error when the DI framework tries to inject into the Mediator (which happens automatically). This would be exactly the same for Constructor injection. A draw.</p>
<p>If we are instantiating the Mediator manually (in a unit test for example), and we don&#8217;t manually inject into it with our DI framework, then setter injection is obviously weaker &#8211; we won&#8217;t get the DI RTE, we&#8217;ll just get a null-pointer exception at some point in our test. Constructor injection is much better here, but something Misko overlooks is that constructor injection is more prone to human error from the inside. We have at least three places where we can forget to properly take care of our dependencies:</p>
<ol>
<li>We might declare the dependency in our constructor argument list, but then forget to store the passed value inside our constructor.</li>
<li>We might declare a property on the class itself but then forget to ask for it in the ctor argument list.</li>
<li>We might even be so delirious as to incorrectly assign the values in our ctor by excluding &#8220;this.&#8221;.</li>
</ol>
<p>None of those mistakes will cause a compile-time error. As with setter injection, we&#8217;ll just get a RTE at some point. Again, a draw.</p>
<p>When we consider what a Mediator is, and the fact that Mediators are amongst the biggest candidates for re-factoring (we might start with one Mediator for a complex nested view, for example, and then break it out into several finely grained Mediators later), setter injection becomes even more convenient. Constructor injection requires more effort when dependencies change: 3 places need editing, including the constructor&#8217;s method signature &#8211; necessitating external changes for any manually instantiated instances.</p>
<h2>Inconsistent State</h2>
<p>Another charge against setter injection is that it can be responsible for objects in inconsistent states: directly after construction, and before injection has occurred, the object is not quite ready for use (it&#8217;s dependencies are missing). But this isn&#8217;t much of a problem when your architectural framework handles that side of things automatically &#8211; it instantiates and injects things for you.</p>
<h2>Hybrids In Progress, A Sliding Scale</h2>
<p>I&#8217;d also like to touch on the mixing of injection styles. Some people see this as akin to mixing coding standards in a project &#8211; ugly. At the same time, setter injection must be used under certain conditions (circular dependencies for example), so even purists have to mix styles sometimes. I&#8217;ve chosen to roll with it, and use what makes the most sense for the case at hand. Looking at actors in the <a title="RobotLegs AS3 - DI Driven MVCS Framework for Flash and Flex" href="http://shaun.boyblack.co.za/blog/2009/04/16/robotlegs-an-as3-mvcs-framework-for-flash-and-flex-applications-inspired-by-puremvc/">RobotLegs</a> framework, I&#8217;m inclined towards:</p>
<ul>
<li>Setter injection for Mediators</li>
<li>Setter injection for Commands</li>
<li>Constructor injection for Proxies</li>
<li>Constructor injection for Services</li>
<li>Constructor injection for non-framework entities</li>
</ul>
<p>My reasoning is that:</p>
<ul>
<li>Mediators and Commands generally have more dependencies and require refactoring more frequently</li>
<li>Proxies and Services should have very few dependencies</li>
<li>Non-framework entities are more likely to be created manually</li>
</ul>
<p>If we look at setter vs ctor injection on a sliding scale, we have:</p>
<ul>
<li>setter -&gt; constructor</li>
<li>convenient -&gt; safe</li>
</ul>
<p>We can always migrate from setter to ctor injection as classes settle down and their refactoring likelihood decreases:</p>
<ul>
<li>setter -&gt; constructor</li>
<li>sketchy -&gt; final</li>
</ul>
<p>Mediators, by their very nature, are the sketchiest parts of an application: they are tightly coupled both to the application and the view. Commands are coupled to the application. There is very little need to make either of these actors &#8220;safe&#8221; or &#8220;final&#8221;, and for flexibility it is wise to leave them &#8220;convenient&#8221;.</p>
<p>Proxies and Services, however, should not be too coupled to the application. They should be the &#8220;safest&#8221; most &#8220;final&#8221; classes in the interests of loose coupling and portability. I would start with setter injection and migrate to constructor injection as those components mature.</p>
<h2>Prompted By:</h2>
<p>This <a href="http://shaun.boyblack.co.za/blog/2009/04/29/another-architectural-framework-but-why/comment-page-1/#comment-3473">comment</a>, thanks!</p>
]]></content:encoded>
			<wfw:commentRss>http://shaun.boyblack.co.za/blog/2009/05/01/constructor-injection-vs-setter-injection/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Another Architectural Framework, But Why?</title>
		<link>http://shaun.boyblack.co.za/blog/2009/04/29/another-architectural-framework-but-why/</link>
		<comments>http://shaun.boyblack.co.za/blog/2009/04/29/another-architectural-framework-but-why/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 14:47:15 +0000</pubDate>
		<dc:creator>shaun</dc:creator>
				<category><![CDATA[Banter]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Robotlegs]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[crybaby]]></category>
		<category><![CDATA[dependency injection]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[smartypants-ioc]]></category>

		<guid isPermaLink="false">http://shaun.boyblack.co.za/blog/?p=406</guid>
		<description><![CDATA[The State Of The Game There are some great Flash and Flex application frameworks out there right now. Mate, Swiz and PureMVC (update: and Parsley!) stand out. The authors of these frameworks realized that the Flash Platform is different enough to the JVM to warrant a fresh approach to application design. Someone mentioned recently that for such a young language (referring to Action Script 3), it&#8217;s quite surprising how many frameworks have sprung up around it. I&#8217;m not surprised at &#8230; <a href="http://shaun.boyblack.co.za/blog/2009/04/29/another-architectural-framework-but-why/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-458" title="robotlegssketchsmall" src="http://shaun.boyblack.co.za/blog/wp-content/uploads/2009/04/robotlegssketchsmall.gif" alt="robotlegssketchsmall" width="221" height="260" /></p>
<h2>The State Of The Game</h2>
<p>There are some great Flash and Flex application frameworks out there right now. <a title="Mate Flex Framework" href="http://mate.asfusion.com/">Mate</a>, <a title="The Swiz Framework" href="http://code.google.com/p/swizframework/">Swiz</a> and <a title="PureMVC Flash and Flex Framework" href="http://puremvc.org/">PureMVC</a> (update: and <a title="Parsley" href="http://www.spicefactory.org/parsley/">Parsley</a>!) stand out. The authors of these frameworks realized that the Flash Platform is different enough to the <a title="The Java Virtual Machine" href="http://en.wikipedia.org/wiki/Java_Virtual_Machine">JVM</a> to warrant a fresh approach to application design.</p>
<p><span id="more-406"></span>Someone mentioned recently that for such a young language (referring to Action Script 3), it&#8217;s quite surprising how many frameworks have sprung up around it. I&#8217;m not surprised at all: rich internet application development is complicated.. and it&#8217;s a pretty recent field in the grand scheme of things. It brings new (and often subtle) twists to traditional web and desktop software development. Writing elegant, maintainable code is hard enough as it is, but doing so on a rapidly evolving, heavily interactive platform.. well, people are still working on the best way to approach that (unless I missed the big news &#8211; in which case you can stop reading right here).</p>
<p>Hence all the groovy new architectural frameworks popping up. They share some common goals:</p>
<ol>
<li>Help developers write good, clean, understandable, testable, maintainable code</li>
<li>Help them write that code faster</li>
<li>Provide an easy-to-use mechanism for application/context/module subsystem inter-communication</li>
<li>Provide an easy-to-use mechanism for wiring distinct parts of the application together whilst keeping those parts loosely coupled</li>
</ol>
<p>And they succeed. To various degrees. I think they&#8217;re all pretty cool.</p>
<p><img class="alignnone size-full wp-image-439" title="scenery" src="http://shaun.boyblack.co.za/blog/wp-content/uploads/2009/04/scenery.gif" alt="scenery" width="450" height="370" /></p>
<h2>A Poke In The Back With A Sharp Stick</h2>
<h3>So why build another one?</h3>
<ol>
<li>For fun &#8211; it&#8217;s how I learn stuff</li>
<li>Because I find the other frameworks critically flawed</li>
</ol>
<h3>What kind of &#8220;critical&#8221; flaws?</h3>
<ol>
<li>Singletons (big &#8220;S&#8221;)</li>
<li>Central/Static Event Dispatchers</li>
<li>Using the Display List as an Application Event Bus</li>
<li>Casting</li>
<li>The Service/Model Locator Pattern</li>
<li>The Presenter Pattern</li>
<li>Injecting into View Components</li>
</ol>
<h3>And what&#8217;s wrong with those things?</h3>
<p>They are bad ideas:</p>
<h4>1. The Singleton &#8211; Bad Idea</h4>
<p>The standard <a href="http://misko.hevery.com/2008/08/17/singletons-are-pathological-liars/">Singleton</a> <a href="http://misko.hevery.com/2008/08/21/where-have-all-the-singletons-gone/">implementation</a> (that static getInstance method) <a href="http://misko.hevery.com/2008/08/25/root-cause-of-singletons/">is</a> <a href="http://tech.puredanger.com/2007/07/03/pattern-hate-singleton/">severely</a> <a href="http://c2.com/cgi/wiki?SingletonsAreEvil">flawed</a>. Unless you are writing device drivers, there is almost no excuse to touch a Singleton with a sharp stick.</p>
<p>Singletons bring bags of hurt to frameworks and applications.. suddenly, trying to build a modular application becomes an overly complicated affair, and unit testing becomes a nightmare. Singletons are viruses &#8211; they infect every class they touch.</p>
<p>And Multitons? If Singletons are evil, Multitons are diabolically evil. What makes the Multiton pattern incredible is that it manages to chump the Singleton as the worst Design Pattern Of All Time &#8211; no easy feat, and certainly the work of an evil genius with a wicked sense of humour. Not only do we have all the problems of the classic Singleton, we throw a poorly designed Model Locator into the mix &#8211; to pull out these horrendous Singletons we now need to use String keys.</p>
<p>Contextual singletons (as made possible by Dependency Injection frameworks) are a much nicer solution, they don&#8217;t require any extra (fluffy, nonsense, ill placed) code on the target classes themselves, and they allow identical applications/modules to exist side-by-side in the Virtual Machine without fighting and mass confusion. Which leads me to..</p>
<h4>2. Central/Static Event Dispatchers &#8211; Bad Idea</h4>
<p>As convenient as it is to use, a Central Dispatcher is a really bad idea. Another Singleton effectively. Pop two apps into the same SWF and watch, with excitement and glee, all the cross-talk that occurs &#8211; both apps responding to each other&#8217;s events. Oh noes!</p>
<p>Architectural frameworks generally provide you with an application event bus/channel/dispatcher to &#8220;chat&#8221; on, but this should be localised to the application itself (or some other context). Which leads me to&#8230;</p>
<h4>3. Using the Display List as an Application Event Bus &#8211; Bad Idea</h4>
<p>I find this one fairly disturbing too: dispatching system/application events along the display list. No!</p>
<p>A View is just that: &#8220;<strong>A</strong> view&#8221;, not &#8220;<strong>The</strong> view&#8221;. And don&#8217;t get me started on those innocent looking Event Maps! No, let&#8217;s move along&#8230;</p>
<h4>4. Casting &#8211; Bad Idea</h4>
<p>Besides wasting space and annoying programmers, casting distributes knowledge throughout a system &#8211; casting requires that you look elsewhere in your codebase for the &#8220;real&#8221; type.</p>
<p>And it weakens our lovely compile-time type checking (albeit temporarily), sending us back in time to our unhappy days building complex applications in the Flash IDE. And it&#8217;s boring. And it often occurs because of..</p>
<h4>5. The Service/Model Locator Pattern &#8211; Bad Idea</h4>
<p>Classes should not be responsible for &#8220;fetching&#8221; their dependencies &#8211; this is a separate responsibility that belongs somewhere else entirely &#8211; they should only contain code for doing their job. When classes reach outside to fetch things from the application/context they sneakily hide their dependencies away from the outside world.</p>
<p>Unit testers will despise you (which is a serious problem if you are writing your own tests) because it becomes incredibly hard to figure out how much set up needs to be done to write even the smallest of tests. You have to look inside the class for any calls to the Service Locator to find your direct dependencies, and then you have to look inside each of those classes to find theirs and so on. No no, that&#8217;s just cruel.</p>
<h4>6. The Presenter Pattern &#8211; Bad Idea</h4>
<p>Ok, it&#8217;s going to be tricky to back this one up. But think about it this way: the Presenter pattern requires that you modify your View component (to add a reference to a Presenter). Not a biggie, but once you&#8217;ve done that you&#8217;ve started coupling your View component to your application/context &#8211; a slippery slope.</p>
<p>I think the Mediator pattern is a much better fit for Flash and it&#8217;s Display List, and even more-so when it comes to Flex (and other UI frameworks with complex component life cycles).</p>
<p>It is far easier and cleaner to &#8220;wrap&#8221; around view components and poke their APIs than to have to modify (extend) them to make space for their Presenter references. Leave those components alone, leave them to the component developers, you&#8217;re supposed to be writing an application. While we&#8217;re on the Presenter pattern, let&#8217;s take a look at something dirty one might do in an attempt to salvage it&#8217;s reputation..</p>
<h4>7. Injecting into View Components &#8211; Bad Idea</h4>
<p>Besides being incredibly slow and wasteful (especially for Flex UIComponents), injecting directly into a View component couples it to your application/context.</p>
<p>View components, with any hope for reuse, should be as self-contained as possible. They should expose an API and dispatch Events. They shouldn&#8217;t be dependent on the application they are in or the framework it happens to be using. Give &#8216;em ViewModels (M-V-VM) if you must, but don&#8217;t go and couple those ViewModels to your application, and certainly don&#8217;t inject them.</p>
<p><img class="alignnone size-full wp-image-467" title="ducksaysyuk1" src="http://shaun.boyblack.co.za/blog/wp-content/uploads/2009/04/ducksaysyuk1.gif" alt="ducksaysyuk1" width="450" height="632" /></p>
<h2>Wrapping Up This Micro-Post</h2>
<h4>Well that&#8217;s just your opinion, dude</h4>
<p>Yeh, but I&#8217;m pretty proud of my little 7 point list there (cos I&#8217;m an OOP noob, and this stuff gets me amped). Using Dependency Injection I was able to avoid all those nasty things when building my own PureMVC-like framework.</p>
<h4>But that just shifts the problem somewhere else</h4>
<p>Yes, somewhere more appropriate.</p>
<p>Besides some convenient implementations (in the mvcs package), and some marker interfaces (in the core package) <a title="RobotLegs AS3 - DI Driven MVCS Framework for Flash and Flex" href="http://shaun.boyblack.co.za/blog/2009/04/16/robotlegs-an-as3-mvcs-framework-for-flash-and-flex-applications-inspired-by-puremvc/">RobotLegs</a> essentially provides two things:</p>
<ol>
<li>A Command Factory &#8211; for binding Commands to Events, and</li>
<li>A Mediator Factory &#8211; for handling automatic Mediator creation and registration</li>
</ol>
<p>Everything else is handled by a Dependency Injection framework and an Event Dispatcher.</p>
<p><img class="alignnone size-full wp-image-459" title="theendissmall" src="http://shaun.boyblack.co.za/blog/wp-content/uploads/2009/04/theendissmall.gif" alt="theendissmall" width="225" height="152" /></p>
<p><strong>Note</strong>: If you&#8217;ve been through all this before, I apologise, it&#8217;s new to me.. I&#8217;m a little slow.</p>
<p><strong>Beware</strong>: the current default implementation of <a title="RobotLegs AS3" href="http://shaun.boyblack.co.za/blog/robotlegs-as3/">RobotLegs</a> makes use of annotated setter injection. This breaks encapsulation, is open to misuse, and runs the risk of leaving objects in partially initialised states, but it&#8217;s very convenient! You can swap out SmartyPants-IOC for a Dependency Injection framework that performs constructor injection if you really want to play it safe.</p>
<p><strong>I&#8217;ll admit straight-up</strong> (albeit as a footnote) that I never really gave Cairngorm much of a chance &#8211; preliminary research led me to demos, documentation and diagrams that screamed poor design and foreshadowed immense struggle. I&#8217;m sure there is a way to build a well designed Cairngorm application, but it looks like it&#8217;d take an awful amount of effort.. and code. And it probably wouldn&#8217;t be very much fun.</p>
<p><strong>UPDATE</strong>: Removed some words that made me sound like a douche bag.</p>
]]></content:encoded>
			<wfw:commentRss>http://shaun.boyblack.co.za/blog/2009/04/29/another-architectural-framework-but-why/feed/</wfw:commentRss>
		<slash:comments>39</slash:comments>
		</item>
		<item>
		<title>RobotLegs AS3: A DI Driven MVCS Framework for Flash &amp; Flex &#8211; Inspired by PureMVC</title>
		<link>http://shaun.boyblack.co.za/blog/2009/04/16/robotlegs-an-as3-mvcs-framework-for-flash-and-flex-applications-inspired-by-puremvc/</link>
		<comments>http://shaun.boyblack.co.za/blog/2009/04/16/robotlegs-an-as3-mvcs-framework-for-flash-and-flex-applications-inspired-by-puremvc/#comments</comments>
		<pubDate>Thu, 16 Apr 2009 03:07:53 +0000</pubDate>
		<dc:creator>shaun</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Resources]]></category>
		<category><![CDATA[Robotlegs]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[dependency injection]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[mvcs]]></category>
		<category><![CDATA[puremvc]]></category>
		<category><![CDATA[smartypants-ioc]]></category>

		<guid isPermaLink="false">http://shaun.boyblack.co.za/blog/?p=314</guid>
		<description><![CDATA[Want a framework like PureMVC but without Singletons, Service Locators, or casting? Perhaps one with Dependency Injection and Automatic Mediator Registration? Well, you might enjoy RobotLegs AS3: yet another lightweight micro-architecture for Rich Internet Applications. It&#8217;s got the bits that I like about PureMVC (Mediators, Commands and Proxies) without any of the bits that I&#8217;m not so fond of (Service Locator, Singletons, casting casting casting!). I&#8217;ve put the source up on GitHub, so feel free to Fork it and make &#8230; <a href="http://shaun.boyblack.co.za/blog/2009/04/16/robotlegs-an-as3-mvcs-framework-for-flash-and-flex-applications-inspired-by-puremvc/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://wiki.github.com/darscan/robotlegs"><img class="alignleft size-full wp-image" style="margin: 0px 10px 0px 0pt;" title="RobotLegs AS3" src="http://shaun.boyblack.co.za/blog/wp-content/uploads/2009/04/robotlegslogotiny.png" alt="RobotLegs AS3" width="50" height="50" /></a>Want a framework like PureMVC but without Singletons, Service Locators, or casting? Perhaps one with Dependency Injection and Automatic Mediator Registration?</p>
<p>Well, you might enjoy RobotLegs AS3: yet another lightweight micro-architecture for Rich Internet Applications.</p>
<p><span id="more-314"></span>It&#8217;s got the bits that I like about PureMVC (Mediators, Commands and Proxies) without any of the bits that I&#8217;m not so fond of (Service Locator, Singletons, casting casting casting!).</p>
<p>I&#8217;ve put the source up on GitHub, so feel free to Fork it and make it better:</p>
<p><a title="Robotlegs on GitHub" href="http://github.com/robotlegs/robotlegs-framework">http://github.com/robotlegs/robotlegs-framework</a></p>
<p>Discussion Group:</p>
<p><a title="RobotLegs AS3 Issues" href="http://github.com/darscan/robotlegs/issues"></a><a title="RobotLegs AS3 Discussion Group" href="http://groups.google.com/group/robotlegs">http://groups.google.com/group/robotlegs</a></p>
<p>Here&#8217;s a little demo:<br />
(<strong>Please note</strong>: the API and usage has cleaned up a lot since this demo was built)</p>
<p><a href="http://examples.robotlegs.org/helloflex/"><img class="alignnone size-full wp-image-327" title="RobotLegs Demo App: HelloFlex" src="http://shaun.boyblack.co.za/blog/wp-content/uploads/2009/04/helloflex460.png" alt="RobotLegs Demo App: HelloFlex" width="460" height="460" /></a></p>
<p>You can also view the demo <a title="RobotLegs Demo - HelloFlex" href="http://examples.robotlegs.org/helloflex/">here</a> (with view source).</p>
<p>The demo app is perhaps not so great, but it demonstrates many of the framework&#8217;s features. AND, there isn&#8217;t a single cast in there! No actor casting, no payload casting, not any casting, not even for fun!</p>
<p>I have much to say about this little framework, but it&#8217;s the wrong side of 5am and I&#8217;ve had a crazy long day. In the meantime, you can find some background info <a title="AS3 Dependency Injection and [Autowire]" href="http://shaun.boyblack.co.za/blog/2009/03/13/as3-dependency-injection-and-autowire/">here</a> and <a title="Flexible RIA Architecture" href="http://shaun.boyblack.co.za/blog/2009/02/08/flexible-ria-architecture-puremvc-and-mate/">here</a> if you&#8217;re interested.</p>
<p><strong>Update: <a title="Robotlegs AS3" href="http://www.robotlegs.org/">RobotLegs Lives!</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://shaun.boyblack.co.za/blog/2009/04/16/robotlegs-an-as3-mvcs-framework-for-flash-and-flex-applications-inspired-by-puremvc/feed/</wfw:commentRss>
		<slash:comments>37</slash:comments>
		</item>
		<item>
		<title>AS3 Dependency Injection and [Autowire]</title>
		<link>http://shaun.boyblack.co.za/blog/2009/03/13/as3-dependency-injection-and-autowire/</link>
		<comments>http://shaun.boyblack.co.za/blog/2009/03/13/as3-dependency-injection-and-autowire/#comments</comments>
		<pubDate>Fri, 13 Mar 2009 13:33:24 +0000</pubDate>
		<dc:creator>shaun</dc:creator>
				<category><![CDATA[Banter]]></category>
		<category><![CDATA[Pijin]]></category>
		<category><![CDATA[Robotlegs]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[mate]]></category>
		<category><![CDATA[puremvc]]></category>
		<category><![CDATA[smartypants-ioc]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[swiz]]></category>

		<guid isPermaLink="false">http://shaun.boyblack.co.za/blog/?p=204</guid>
		<description><![CDATA[Warning: This is long and probably VERY boring.. unless you are an AS3 junkie, and you&#8217;re interested in so called &#8220;lightweight micro-architectural frameworks&#8221; for Flash and Flex. A couple of weeks ago I played around with Mate and Swiz. I already knew a little about Dependency Injection (in theory anyway), but playing with those two frameworks really drove the point home: applications are potentially MUCH easier to write, and much more flexible, when you take advantage of Dependency Injection. If &#8230; <a href="http://shaun.boyblack.co.za/blog/2009/03/13/as3-dependency-injection-and-autowire/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><strong>Warning</strong>: This is long and probably VERY boring.. unless you are an AS3 junkie, and you&#8217;re interested in so called &#8220;lightweight micro-architectural frameworks&#8221; for Flash and Flex.</p>
<p>A couple of weeks ago I played around with <a title="Mate Flex Framework" href="http://mate.asfusion.com/" target="_blank">Mate</a> and <a title="Swiz Flex Framework" href="http://code.google.com/p/swizframework/" target="_blank">Swiz</a>. I already knew a little about Dependency Injection (in theory anyway), but playing with those two frameworks really drove the point home: applications are potentially MUCH easier to write, and much more flexible, when you take advantage of Dependency Injection.<span id="more-204"></span></p>
<p>If you&#8217;ve used <a title="PureMVC Framework" href="http://puremvc.org/" target="_blank">PureMVC</a> you might be familiar with writing code like this:</p>
<p>var myProxy:MyProxy = facade.retrieveProxy(MyProxy.NAME) as MyProxy;<br />
myProxy.doSomethingAwesome();</p>
<p>This is sometimes referred to as the Model or Service Locator pattern. Firstly, it&#8217;s a little tedious to write. But more importantly, it puts the responsibility on your class to &#8220;fetch&#8221; the things it needs &#8211; not a good thing (especially from a testing point of view). From the &#8220;outside&#8221; you can&#8217;t see what your class is dependant on: you have to review the actual code in your class to see what it wants to pull in from the outside world.</p>
<p>It&#8217;s also a bit sneaky: to get something out, you have to know how it was put in &#8211; splitting and spreading knowledge across your codebase. Not pleasant.</p>
<p>Alternatively, you could use a Singleton to hang all your objects on. That would not be cool: <a title="Singletons are Pathological Liars" href="http://misko.hevery.com/2008/08/17/singletons-are-pathological-liars/" target="_blank">link</a>, <a title="Where Have All the Singletons Gone?" href="http://misko.hevery.com/2008/08/21/where-have-all-the-singletons-gone/" target="_blank">link</a>, <a title="Root Cause of Singletons" href="http://misko.hevery.com/2008/08/25/root-cause-of-singletons/" target="_blank">link</a>.</p>
<p><strong>Enter Dependency Injection</strong></p>
<p>Another solution is to declare certain properties on your class as dependencies to be &#8220;given&#8221; to you on (or just after) construction. A Dependency Injection framework will take care of managing these dependencies and providing you with what you need. Your class can then focus on doing it&#8217;s job instead of worrying about how to get the objects it needs.</p>
<p><strong>I Like The Mediator Pattern</strong></p>
<p>And I like the concepts in PureMVC: Specifically the Mediator, Command and Proxy patterns. I like clean view components with absolutely no framework or application code in them &#8211; as made possible by the Mediator pattern. I like Commands and I like binding them to system events. I like Proxies, who only communicate outwards, by dispatching events, and who&#8217;s APIs must be accessed directly by Commands and/or Mediator instances.</p>
<p>But I don&#8217;t like the use of Singletons or Multitons, the Service/Model locator pattern, the spreading of knowledge throughout the system by the Mediator and Proxy registration and retrieval mechanism (you have to know how something was put in to get it out again), and the custom Notification scheme and it&#8217;s associated methods: listNotificationInterests and handleNotification (with that nasty switch!).</p>
<p>So, I like PureMVC, I just think it could be improved for certain use cases. Now, obviously, improvement is subjective. Designing a framework is largely a balancing act: every decision has a pro and a con, and the framework architect must weigh up the pros and cons to steer the project in a chosen direction. That direction is determined by the architects vision of the most important use cases for the framework. I think that PureMVC has been brilliantly designed when stacked against it&#8217;s objectives. It&#8217;s been very carefully thought through, has an amazing author and community, sports great documentation, examples and utilities, and does it&#8217;s job well.</p>
<p><strong>YALMAFRIA (Yet Another Lightweight Micro-Architecture For Rich Internet Applications)</strong></p>
<p>Mate and Swiz can both do Dependency Injection. What I found interesting about the Dependency Injection in Mate is that it&#8217;s event based &#8211; this allows you to look at the event target to determine the instance that is currently being injected into. Using that (and a thing called an Object Builder in Mate) I was able to configure my application to automatically create Mediators for view components as they arrived on stage, and set references to the view components on the newly created Mediators.</p>
<p>It worked, but it seemed a little klunky, and still required a fair amount of code to map a Mediator Class to a view component Class (and any other dependencies). Regardless, it got me amped &#8211; using Dependency Injection and automatic Mediator registration I could remove most of the boring (and brittle) code from my projects.</p>
<p>I decided not to use Swiz or Mate in the end. Both offer nice solutions to some of the challenges of building RIA applications, but neither would make building my current application any quicker or easier.</p>
<p>Besides: I didn&#8217;t like the idea of using the display list as a system event channel, as in the case of Mate, or the concept of a central (Singleton) event dispatcher, as in the case of Swiz. And I didn&#8217;t want to put ANY application or framework code into my view components, as both seem to encourage.</p>
<p>Also, I wanted a framework that I could use for both Flex AND plain AS3 projects. I believe that this is possible with Swiz, but certainly not with Mate.</p>
<p>So, I looked for an AS3 Dependency Injection library to build a(nother) micro-architectural framework on top of..</p>
<p><strong>Back to Dependency Injection</strong></p>
<p>I tried <a title="Spring ActionScript" href="http://www.pranaframework.org/" target="_blank">Spring ActionScript</a> (previously known as Prana) first. Immediately, two things bugged me about it: the use of external xml files to configure dependencies, and the side-effect of that requirement:</p>
<p>When compiling a SWF the compiler ignores Class definitions that are not directly referenced by the application. A small problem, easily solved, but an extra step none the less to ensure all necessary Classes are compiled. Loading your dependencies externally is groovy, fo sho, but I really don&#8217;t need that right now.</p>
<p>I believe you&#8217;d enjoy Spring ActionScript if you&#8217;re from Java land (hello there, have you played with <a title="Clojure" href="http://clojure.org/" target="_blank">Clojure</a> yet? it got me all jazzed for a spell.. even though I didn&#8217;t build anything useful with it).</p>
<p>Anyhoo.. check this out if you are interested in Spring ActionScript and Autowiring: <a title="The “Spring ActionScript” Framework – Part 2: Autowiring" href="http://coenraets.org/blog/2009/03/the-spring-actionscript-framework-%E2%80%93-part-2-autowiring/" target="_blank">link</a></p>
<p>Or this, if you want to see how to do a similar thing with Swiz: <a title="A lovely little framework called Swiz" href="http://aralbalkan.com/1960" target="_blank">link</a></p>
<p><strong>Inspired by Guice</strong></p>
<p>Next I checked out <a title="SmartyPants-IOC Dependency Injection Framework" href="http://code.google.com/p/smartypants-ioc/" target="_blank">SmartyPants-IOC</a>. I liked the vibe and proceeded to build my little framework with it.</p>
<p><strong>RobotLegs AS3<br />
</strong></p>
<p>I decided to call my framework RobotLegs. It&#8217;s very simple really. It contains two factories (and some Interfaces):</p>
<p>A Mediator Factory &#8211; for automatically creating and wiring up Mediators as view components arrive on Stage.</p>
<p>And a Command Factory &#8211; for binding commands to events.</p>
<p>Everything else is handled by Dependency Injection thanks to SmartyPants. Conceptually, the framework is much the same as PureMVC, but uses DI in place of a registry, and built-in Flash Events instead of Notifications.</p>
<p>I was able to migrate my current project over to Robot Legs (from PureMVC) in about a day. Not bad considering there were dozens of Commands, over 20 Mediators and around 10 Proxies to convert. It was a bit of a mission creating all the custom Event Classes to replace my Notifications though.</p>
<p>But it was certainly worth it. My application code has tidied up nicely. Many of my Mediators, Proxies and Commands have halved in size, due to the removal of lookup code and notification body casting.</p>
<p><strong>RobotLegs?</strong></p>
<p>The cool thing about Mediators that automatically wrap themselves around view components as they appear is that it greatly simplifies dealing with composite, lazily instantiated view components. I don&#8217;t need to worry about how a view component comes into being, I just set up a rule that ensures when that view components arrives I have a Mediator to link it back into the application. This is great for items inside Tab Navigators, Accordians, View Stacks etc.</p>
<p>It does present a little problem however: context. When you manually create and register a Mediator, you have the opportunity to give it some context, such as setting a property on it. Mediators that get automatically created make this a bit tricky. We could, of course, set that property on the view component, to be picked up by the Mediator on registration, but that&#8217;s not cool &#8211; view components should be self-contained, stand-alone widgets.</p>
<p>My current solution is to allow Mediators to request properties from parent Mediators. This is made possible by the Mediator Factory, with it&#8217;s dictionary of currently registered Mediators and view components, and a method declared by the Mediator Interface called &#8220;provideProperty&#8221;.</p>
<p>I plan on releasing Robot Legs once it has settled down a bit &#8211; using it in my current project has pointed out a great many things that I had overlooked initially. It won&#8217;t be everyone&#8217;s cup of tea &#8211; nothing is <img src='http://shaun.boyblack.co.za/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>UPDATE: RobotLegs 0.1, with demo Flex app, has been released.</strong> More info here:</p>
<p><a title="RobotLegs - an MVCS framework for Flash and Flex" href="http://shaun.boyblack.co.za/blog/2009/04/16/robotlegs-an-as3-mvcs-framework-for-flash-and-flex-applications-inspired-by-puremvc/">http://shaun.boyblack.co.za/blog/2009/04/16/robotlegs-an-as3-mvcs-framework-for-flash-and-flex-applications-inspired-by-puremvc/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://shaun.boyblack.co.za/blog/2009/03/13/as3-dependency-injection-and-autowire/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
		<item>
		<title>Flexible RIA Architecture: PureMVC and Mate</title>
		<link>http://shaun.boyblack.co.za/blog/2009/02/08/flexible-ria-architecture-puremvc-and-mate/</link>
		<comments>http://shaun.boyblack.co.za/blog/2009/02/08/flexible-ria-architecture-puremvc-and-mate/#comments</comments>
		<pubDate>Sun, 08 Feb 2009 14:01:49 +0000</pubDate>
		<dc:creator>shaun</dc:creator>
				<category><![CDATA[Resources]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[mate]]></category>
		<category><![CDATA[puremvc]]></category>

		<guid isPermaLink="false">http://shaun.boyblack.co.za/blog/?p=170</guid>
		<description><![CDATA[I&#8217;ve been using PureMVC for my Flash/Flex applications for quite a while now, and have generally found it to work quite well. Besides the obviously annoying abundance of boiler-plate code, it does a decent job of separating concerns, and has helped me to build better applications. Lately, however, I&#8217;ve been building an application for which PureMVC has turned out to be a pretty poor fit. The term that some people have used to describe this kind of application is &#8220;Document-Based&#8221;. &#8230; <a href="http://shaun.boyblack.co.za/blog/2009/02/08/flexible-ria-architecture-puremvc-and-mate/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using <a title="PureMVC" href="http://puremvc.org" target="_blank">PureMVC</a> for my Flash/Flex applications for quite a while now, and have generally found it to work quite well. Besides the obviously annoying abundance of boiler-plate code, it does a decent job of <a title="Separation Of Concerns" href="http://en.wikipedia.org/wiki/Separation_of_concerns" target="_blank">separating concerns</a>, and has helped me to build better applications.</p>
<p>Lately, however, I&#8217;ve been building an application for which PureMVC has turned out to be a pretty poor fit. The term that some people have used to describe this kind of application is <a title="Document Based" href="http://code.google.com/p/mate-examples/wiki/DocumentBased" target="_blank">&#8220;Document-Based&#8221;</a>.</p>
<p><span id="more-170"></span></p>
<p>A benefit of <a title="Model View Controller" href="http://en.wikipedia.org/wiki/Model-view-controller" target="_blank">MVC</a> is the ability to easily create multiple Views of the same Model. Document-based is roughly the opposite of that: the ability to create identical Views of different data. Think OS X Finder (or Windows Explorer if you must!): multiple windows that look and function the same but show different parts of your filesystem.</p>
<p>I spend a lot of my time trying to learn as much as possible about programming. This means subscribing to a huge number of feeds and <a title="Shaun's Bookmarks" href="http://delicious.com/shaunphilipsmith" target="_blank">bookmarking</a> obsessively! Looking for solutions to my current problem I re-discovered <a title="Mate Flex Framework" href="http://mate.asfusion.com/" target="_blank">Mate</a>. I hadn&#8217;t looked too deeply into it before as I needed an ActionScript Framework that wasn&#8217;t bound to the Flex Framework (ruling out pretty much every framework except for PureMVC). This time however, I didn&#8217;t mind binding(!) myself to Flex.</p>
<p>Central to Mate is the concept of an <a title="Mate Event Map" href="http://mate.asfusion.com/page/documentation/tags/eventmap" target="_blank">Event Map</a>. UI components dispatch events that bubble up the display list and get caught by one or more Event Maps: loosely coupled goodness. Mate also employs <a title="Dependency Injection" href="http://en.wikipedia.org/wiki/Dependency_injection" target="_blank">Dependency Injection</a> instead of the <a title="Service Locator" href="http://blog.iconara.net/2008/12/13/architectural-atrocities-part-10-cairngorms-service-locator/" target="_blank">Service/Model Locator</a> pattern used by <a title="Cairngorm Flex Framework" href="http://labs.adobe.com/wiki/index.php/Cairngorm" target="_blank">Cairngorm</a> and <a title="PureMVC Framework" href="http://puremvc.org/" target="_blank">PureMVC</a>. And no <a title="Flaw: Brittle Global State &amp; Singletons" href="http://misko.hevery.com/code-reviewers-guide/flaw-brittle-global-state-singletons/" target="_blank">Singletons</a>! Suitably impressed.</p>
<p>I highly recommend you check out <a title="Mate Flex Framework" href="http://mate.asfusion.com/" target="_blank">Mate</a>, and if I were you I&#8217;d do it in this order:</p>
<ul>
<li><a title="Mate Presentation at 360 Flex" href="http://link.brightcove.com/services/player/bcpid1733261879?bclid=1729365228&amp;bctid=1738801386" target="_blank">Mate Presentation</a> by Laura Arguello: fairly long, and a bit slow, but quite fun and covers some really important concepts &#8211; not just for Mate, but application architecture in general</li>
<li><a title="Hello Mate" href="http://nwebb.co.uk/blog/?page_id=241" target="_blank">Hello Mate</a> by Neil Webb</li>
<li><a title="Mate Overview" href="http://mate.asfusion.com/page/documentation/overview" target="_blank">Mate Overview</a></li>
<li><a title="Mate Document Based Example" href="http://code.google.com/p/mate-examples/wiki/DocumentBasedExampleIntro" target="_blank">Mate Document-Based Example</a> by Theo Hultberg/Iconara: lots of great info</li>
</ul>
<p>Ok, time for me to calculate how painful it&#8217;s going to be to switch my application over to Mate.</p>
<p><strong>UPDATE</strong>: I posted my thoughts (as best as I could gather them) on the PureMVC forum here:</p>
<p><a title="PureMVC Forum Topic: Document-Based" href="http://forums.puremvc.org/index.php?topic=1000.0">http://forums.puremvc.org/index.php?topic=1000.0</a></p>
<p><strong>UPDATE</strong>: I decided not to switch to Mate for my current project. I wrote a little MVC framework (much like PureMVC), that uses Dependency Injection, and switched to that instead. More here:</p>
<p><a title="Pijin.net V3 progress" href="http://shaun.boyblack.co.za/blog/2009/02/24/pijinnet-v3-progress-update-24-feb-2009/">http://shaun.boyblack.co.za/blog/2009/02/24/pijinnet-v3-progress-update-24-feb-2009/</a><br />
<a title="AS3 DI and Autowire" href="http://shaun.boyblack.co.za/blog/2009/03/13/as3-dependency-injection-and-autowire/">http://shaun.boyblack.co.za/blog/2009/03/13/as3-dependency-injection-and-autowire/</a></p>
<p><strong>MAJOR UPDATE: RobotLegs 0.1, with demo Flex app, has been released.</strong> More info here:</p>
<p><a title="RobotLegs - an MVCS framework for Flash and Flex" href="http://shaun.boyblack.co.za/blog/2009/04/16/robotlegs-an-as3-mvcs-framework-for-flash-and-flex-applications-inspired-by-puremvc/">http://shaun.boyblack.co.za/blog/2009/04/16/robotlegs-an-as3-mvcs-framework-for-flash-and-flex-applications-inspired-by-puremvc/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://shaun.boyblack.co.za/blog/2009/02/08/flexible-ria-architecture-puremvc-and-mate/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Interactive Application Architecture</title>
		<link>http://shaun.boyblack.co.za/blog/2008/11/13/interactive-application-architecture/</link>
		<comments>http://shaun.boyblack.co.za/blog/2008/11/13/interactive-application-architecture/#comments</comments>
		<pubDate>Thu, 13 Nov 2008 14:21:02 +0000</pubDate>
		<dc:creator>shaun</dc:creator>
				<category><![CDATA[Resources]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[cairngorm]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[mvp]]></category>

		<guid isPermaLink="false">http://shaun.boyblack.co.za/blog/?p=158</guid>
		<description><![CDATA[Just in case you thought that there was a clear cut definition of MVC: http://ctrl-shift-b.blogspot.com/2007/08/interactive-application-architecture.html And if you are considering using Cairngorm for your next project, give this a read (especially the comments, all of them): http://blog.iconara.net/2008/04/13/architectural-atrocities-part-x-cairngorms-model-locator-pattern/]]></description>
			<content:encoded><![CDATA[<p>Just in case you thought that there was a clear cut definition of MVC:</p>
<p><a title="Interactive Application Architecture" href="http://ctrl-shift-b.blogspot.com/2007/08/interactive-application-architecture.html" target="_blank">http://ctrl-shift-b.blogspot.com/2007/08/interactive-application-architecture.html</a></p>
<p>And if you are considering using Cairngorm for your next project, give this a read (especially the comments, all of them):</p>
<p><a title="Architectural Atrocities, part 9: Cairngorm’s Model Locator pattern" href="http://blog.iconara.net/2008/04/13/architectural-atrocities-part-x-cairngorms-model-locator-pattern/" target="_blank">http://blog.iconara.net/2008/04/13/architectural-atrocities-part-x-cairngorms-model-locator-pattern/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://shaun.boyblack.co.za/blog/2008/11/13/interactive-application-architecture/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

