<?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>Nobien &#187; Design Patterns</title>
	<atom:link href="http://blog.nobien.net/category/design-patterns/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.nobien.net</link>
	<description>A nerd blog about nerdy things by ... nerdy guys?</description>
	<lastBuildDate>Mon, 19 Jul 2010 14:27:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>New Flash Community Developments: Robotlegs and Signals</title>
		<link>http://blog.nobien.net/2009/12/14/new-flash-community-developments-robotlegs-and-signals/</link>
		<comments>http://blog.nobien.net/2009/12/14/new-flash-community-developments-robotlegs-and-signals/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 21:19:10 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Frameworks]]></category>

		<guid isPermaLink="false">http://blog.nobien.net/?p=178</guid>
		<description><![CDATA[I've come to realize that I'm always a bit hesitant to change. I was late to get a cell phone, late to join Facebook, late to join Twitter, and often late to look into developments within the Flash community. Lately I've been trying to change how often I tune into Flash community developments. As of [...]]]></description>
			<content:encoded><![CDATA[<p>I've come to realize that I'm always a bit hesitant to change. I was late to get a cell phone, late to join Facebook, late to join Twitter, and often late to look into developments within the Flash community. Lately I've been trying to change how often I tune into Flash community developments. As of late I've stumbled across two projects that struck my fancy: <a href="http://www.robotlegs.org/">Robotlegs</a> and <a href="http://github.com/robertpenner/as3-signals">Signals</a>. Robotlegs is a lightweight MVCS architecture that is very focused on dependency injection. Signals is the result of Robert Penner's frustration with the Flash Player's native event system. Thus he has created an event system inspired by C# events and signals/aslots in Qt. Both looked like interesting projects so I decided to dive into them further. I'll start with robotlegs.</p>
<p><span id="more-178"></span></p>
<p>Having some experience with PureMVC and even having some pleasant success with it, I was quite intrigued by some claims that robotlegs is "<a href="http://jessewarden.com/2009/10/how-to-use-robotlegs-on-top-of-gaia-part-1-of-3-quickstart.html">PureMVC done right</a>". Hmm...At any rate, I can't help but be intrigued by a claim such as this and I always enjoy looking reading about developers' often unwavering opinions about how an MVC pattern should be implemented. So after reading the docs, development forums and checking out the examples, I feel that robotlegs is a great concept and has fulfilled its development philosophy very well. It seems to me that its primary focus has been the use of dependency injection. This allows you to keep the layers of your application nicely decoupled. In my early research, I was a bit annoyed by the fact that the injection module, <a href="http://github.com/tschneidereit/SwiftSuspenders">SwiftSuspenders</a>, was only compatible with the mxmlc compiler. However, the latest version includes the ability to use XML to configure the injection points so I can now use it with the Flash IDE. Yes, I, <em>and a lot of other people</em>, still use the Flash IDE to compile applications.</p>
<p>My only complaint about Robotlegs is very subjective. And let me preface this with the fact that I'm not a classically trained developer (I have a degree in design, not computer science). But Robotlegs was rather difficult to get my head partially wrapped around. More specifically, <a href="http://en.wikipedia.org/wiki/Dependency_injection">dependency injection</a> was, and still is, rather difficult for me to understand. I understand the point of it, but how its implemented in Robotlegs still seems like magic to me. And because I don't understand the dependency injection all that well, its hard for me to feel really comfortable using the framework to develop anything. In comparison, what I really like about <a href="http://puremvc.org/">PureMVC</a> was that it was pretty easy to learn and the core concepts are also easy to understand (at least to me). Regardless, this is not to say that Robotlegs is any better or worse than PureMVC.</p>
<p>Unlike my apprehensiveness for Robotlegs, I am really excited about Robert Penner's <a href="http://github.com/robertpenner/as3-signals">Signals</a> project. I stumbled across this project while researching Robotlegs. I didn't quite understand it at first, but after checking out the source and giving a go I became instantly hooked on the idea and hope I can integrate it into my future projects. Basically what Penner has done is create an event/notification system that can pass around strongly typed objects to listeners instead of the native/traditional <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/events/Event.html">Event</a> object. Signals are, to put it simply, an object that represents an event. Thus a signal object has its own API for registering and unregistering listeners. Signals also gives you the ability to define the types of signals an object should possess in your interfaces. This fulfills one of my biggest wishes for interfaces: a way to define the types of events an object should have to dispatch. As of now the project seems to still be in development with Penner experimenting how to make working with native events a bit easier. I highly recommend looking into his work, but don't expect much as he's apparently in Thailand until the beginning of January.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nobien.net/2009/12/14/new-flash-community-developments-robotlegs-and-signals/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Why No Love for the Monostate Pattern in ActionScript 3?</title>
		<link>http://blog.nobien.net/2008/11/18/why-no-love-for-the-monostate-pattern-in-actionscript-3/</link>
		<comments>http://blog.nobien.net/2008/11/18/why-no-love-for-the-monostate-pattern-in-actionscript-3/#comments</comments>
		<pubDate>Wed, 19 Nov 2008 02:50:56 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Design Patterns]]></category>

		<guid isPermaLink="false">http://blog.nobien.net/?p=96</guid>
		<description><![CDATA[A coworker of mine recently introduced me to the monostate pattern. At first I was like "wtf is that?". I had never heard of that pattern before. He is of the opinion that the monostate pattern is far better than the singleton pattern. I had no opinion on the subject because I only assumed singletons [...]]]></description>
			<content:encoded><![CDATA[<p>A coworker of mine recently introduced me to the monostate pattern. At first I was like "wtf is that?". I had never heard of that pattern before. He is of the opinion that the monostate pattern is far better than the singleton pattern. I had no opinion on the subject because I only assumed singletons are the one and only way to ensure only one instance of an object is created throughout an application.</p>
<p><span id="more-96"></span></p>
<p>At first I gasped in excitement at the thought that there was something possibly, or arguably, better than using singletons. Like I said, I had no real opinion prior, so I spent today researching it. Low and behold, there's hardly any info or examples of implementations of this pattern out there. The only useful info I found was at this <a href="http://www.bigroom.co.uk/blog/better-without-singletons" target="_blank">blog post</a>. But, here is an example of what I gathered a monostate class to look like in ActionScript 3:</p>
<pre class="actionscript">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ApplicationConfiguration
	<span style="color: #66cc66;">&#123;</span>
		protected <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">var</span> _language:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;en&quot;</span>;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> ApplicationConfiguration<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;">get</span> <span style="color: #0066CC;">language</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> _language;
		<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;">language</span><span style="color: #66cc66;">&#40;</span> v:<span style="color: #0066CC;">String</span> <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			_language = v;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre>
<p>So in this case I have a class with a protected static var named _language in it. This variable, because its static, will only ever exist in one place, and thats in the class definition. No matter how many times I create a new ApplicationConfiguration instance, the value of that variable will persist throughout each instance, allowing every instance to have a "mono state". Why didn't I ever think of this before? It's so simple and clever. So here's an example use of this class:</p>
<pre class="actionscript"><span style="color: #000000; font-weight: bold;">var</span> config1:ApplicationConfiguration = <span style="color: #000000; font-weight: bold;">new</span> ApplicationConfiguration<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span> config1.<span style="color: #0066CC;">language</span> <span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// Output: en</span>
config1.<span style="color: #0066CC;">language</span> = <span style="color: #ff0000;">&quot;fr&quot;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> config2:ApplicationConfiguration = <span style="color: #000000; font-weight: bold;">new</span> ApplicationConfiguration<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span> config2.<span style="color: #0066CC;">language</span> <span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// Output: fr</span>
config2.<span style="color: #0066CC;">language</span> = <span style="color: #ff0000;">&quot;es&quot;</span>;
&nbsp;
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span> config1.<span style="color: #0066CC;">language</span> <span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// Output: es</span></pre>
<p>I've commented in the output of that code, and you can see, when I make a change to the language property in config2 the value of language in config1 also changes.</p>
<p>So now I'm wondering what the advantages and disadvantages to this approach over a singleton might be. One of the most obvious advantages I saw right away was the fact that I can easily extend a monostate class. Extending singletons is, well, impossible as far as I know. Other than that I'm not too sure what some major advantages are. But extending seems to be big enough for me to want to start using this pattern.</p>
<p>At any rate, I'd like to hear some comments about anyone's experience with this pattern.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nobien.net/2008/11/18/why-no-love-for-the-monostate-pattern-in-actionscript-3/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Anyone Using PureMVC Multicore For Non-Flex Flash Sites/Apps?</title>
		<link>http://blog.nobien.net/2008/11/16/anyone-using-puremvc-multicore-for-non-flex-flash-sitesapps/</link>
		<comments>http://blog.nobien.net/2008/11/16/anyone-using-puremvc-multicore-for-non-flex-flash-sitesapps/#comments</comments>
		<pubDate>Mon, 17 Nov 2008 00:37:10 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[Frameworks]]></category>

		<guid isPermaLink="false">http://blog.nobien.net/?p=89</guid>
		<description><![CDATA[Lately I've been experimenting with PureMVC. I'm really curious if it could aid in the development of side projects and even projects at work. In fact, I gave it a go on the project I'm currently on at work right now. All started out well, but then I ran into a dilemma. Basically, if you [...]]]></description>
			<content:encoded><![CDATA[<p>Lately I've been experimenting with PureMVC. I'm really curious if it could aid in the development of side projects and even projects at work. In fact, I gave it a go on the project I'm currently on at work right now. All started out well, but then I ran into a dilemma. Basically, if you know anything about PureMVC, a mediator is register for a view component at runtime. Not being a total MVC genius, I figured I'd write some sort of proxy to load a section and register a mediator for the section once it was loaded.</p>
<p><span id="more-89"></span></p>
<p>Let me outline my situation hypothetically...</p>
<p>1. I have an Application class. This class is the document class of an FLA. The application has a navigation component in it. Each navigation button corresponds to a section. Hypothetically these sections are Home, Gallery and News.</p>
<p>2. I have 5 mediators. ApplicationMediator , NavMediator, HomeMediator, GalleryMediator, and NewsMediator. ApplicationMediator and NavMediator are registered in the shell during startup. Note, I'm using the Flash IDE so the Nav component is on the stage already and a child of Application.</p>
<p>3. NavMediator listens for clicks on the nav component and sends out a note to load a section. The ApplicationMediator hears this note and unloads the current section (if there is one) then loads the necessary section into a new Loader object. By default the home nav button is selected to load the home section when the app starts.</p>
<p>4. Once a section is loaded, lets assume its the Home section, the HomeMediator must be registered in the View. This is where I got stumped. Here are my two initial ways of register the mediator:</p>
<p>4.A. After loading is complete, the HomeMediator is registered in the view from ithin ApplicationMediator like so:</p>
<pre class="actionscript">facade.<span style="color: #006600;">regsiterMediator</span><span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span><span style="color: #66cc66;">&#40;</span> HomeMediator<span style="color: #66cc66;">&#40;</span> loader.<span style="color: #006600;">content</span> as <span style="color: #0066CC;">Home</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;</pre>
<p>The problem with this is that it requires HomeMediator be imported into ApplicationMediator (including the mediators for the other sections as well). Additionally, within HomeMediator (and other section nediators), I have a getter for the view component that looks like this:</p>
<pre class="actionscript"><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;">home</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Home</span>
<span style="color: #66cc66;">&#123;</span>
   <span style="color: #b1b100;">return</span> viewComponent as <span style="color: #0066CC;">Home</span>;
<span style="color: #66cc66;">&#125;</span></pre>
<p>This ends up compiling Home (the section's FLA document class) into the main application SWF in addition to HomeMediator. I certainly don't want this to happen. I want all the code for the home section to be contained within the home SWF.</p>
<p>4.B. Rather than register the mediator in the ApplicationMediator, I would register the HomeMediator in the constructor of the Home component similar to the way the Application starts up. Like so:</p>
<pre class="actionscript"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">Home</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
   ApplicationFacade.<span style="color: #006600;">getInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">registerMediator</span><span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> HomeMediator<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">this</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre>
<p>In some cases I would also manually send a notification to initialize the section so that it would run standalone. This method requires that I import ApplicationFacade into the Home component, thus compiling any classes that are imported into that class (commands, and the Application view component) into the Home SWF. I don't want this to happen either because I don't want to bloat each section with main application code.</p>
<p>So therein lies my dilemma. Each section is unloaded when a new section is requested to keep the memory usage of the site/app to a minimum because, in the real project, each section is rather large (some even use Papervision). I'm just totally stumped when to register the mediator for the loaded section without having unnecessary code compiled into the shell or the section.</p>
<p>Also, thanks to Simon for making me rewrite my situation a bit better. It was perhaps a bit confusing before.</p>
<p>I resorted to the PureMVC forums and was told that the Multicore version of PureMVC would solve my problems. I haven't had time to look into Multicore yet, but I was wondering if anyone out there has used the Multicore version on a, what might be, smiliar project (one that loads and unloads sections). Also note, that I'm not using Flex here, I'm using the Flash IDE (and FlashDevelop) to publish my content. So I'd love to hear the thoughts, experiences, etc from any one thats gone this route or has some sort of solution for using the non-multicore version of PureMVC. Thanks in advance.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nobien.net/2008/11/16/anyone-using-puremvc-multicore-for-non-flex-flash-sitesapps/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
