<?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>Fusioncube &#187; design patterns</title>
	<atom:link href="http://www.fusioncube.net/index.php/category/development/design-patterns/feed" rel="self" type="application/rss+xml" />
	<link>http://www.fusioncube.net</link>
	<description>The online journey of a technophile, by Steve Brownlee</description>
	<lastBuildDate>Wed, 01 Feb 2012 04:17:42 +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>I could care less what you say&#8230;</title>
		<link>http://www.fusioncube.net/index.php/i-could-care-less-what-you-say</link>
		<comments>http://www.fusioncube.net/index.php/i-could-care-less-what-you-say#comments</comments>
		<pubDate>Fri, 04 Jun 2010 05:00:26 +0000</pubDate>
		<dc:creator>Steve Brownlee</dc:creator>
				<category><![CDATA[career]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[errata]]></category>
		<category><![CDATA[antipimp]]></category>
		<category><![CDATA[asshat]]></category>
		<category><![CDATA[IoC]]></category>
		<category><![CDATA[just make it work]]></category>
		<category><![CDATA[ORM]]></category>
		<category><![CDATA[personality]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[technology]]></category>

		<guid isPermaLink="false">http://www.fusioncube.net/index.php/i-could-care-less-what-you-say</guid>
		<description><![CDATA[My inspiration for this article is a conference call I had today with some teammates on a project at work. As usual, there&#8217;s a couple application developers, the project manager, throw in a couple QA folks, a BA, etc. This is a complementary article to Antipimp&#8217;s &#8220;I could care less what they say.&#8221;. Read that [...]]]></description>
			<content:encoded><![CDATA[<p>My inspiration for this article is a conference call I had today with some teammates on a project at work. As usual, there&#8217;s a couple application developers, the project manager, throw in a couple QA folks, a BA, etc.</p>
<p>This is a complementary article to Antipimp&#8217;s <a href="http://theantipimp.com/?p=1908">&#8220;I could care less what they say.&#8221;</a>. Read that first if you have a moment, then come back here and finish up.&#160; Take your time, it&#8217;s worth it.&#160; </p>
<p>.</p>
<p>.</p>
<p>Now, let&#8217;s talk about the other side of the fence. </p>
<p>Once you get the awesome job that Asshat Antipimp lined up for you, trust me when I say that no one gives a flip how many lines of code you wrote, or what awesome application framework you used. They care that you solved their problem and that it won&#8217;t break in a month. </p>
<p>Software folks are notorious for their. </p>
<ul>
<li>Oddball personalities </li>
<li>A penchant for useless, esoteric knowledge of science fiction and fantasy literature </li>
<li>Ability to completely disregard all social convention </li>
<li>Expediency in stinking up a room </li>
<li>Many other curious behaviors..</li>
</ul>
<p>My least favorite trait of many of my colleagues is their mistaken belief that other people give a shit about the technology. Well, actually, they do, but only when it doesn&#8217;t work. Things can be sunshine and roses and kisses and hugs for years, but trust me, when you write an application that doesn&#8217;t work, then be prepared to kiss your technology goodbye &#8211; or end up on the street.</p>
<p>The 99% of the world that doesn&#8217;t know how to write a ternary operation sees software as a means to an end, and that&#8217;s it folks. Writing software is &#8220;magic&#8221; to them and I hate to see application developers exploit that fact.</p>
<p align="left">They aren&#8217;t amazed by your ability to use an ORM package.</p>
<p align="left">They don&#8217;t care that you squeezed a few more cool aspects into your IoC architecture.</p>
<p align="left">Then even don&#8217;t care that you&#8217;ve taken the painstaking effort to apply industry-standard usability practices to make it easier for them to work with it.</p>
<p>They. just. want. it. to. work.</p>
<p>Therefore, if you find yourself taking 20 minutes to explain to the eyes-glazed-over, bored-beyond-tears business folks how awesome you are, then it&#8217;s time to shut the hell up, sit down, and let them bicker about the fact that you used the wrong shade of blue in the application header.</p>
<p>Your job is to solve problems and make the lives of other easier. They don&#8217;t understand what you do, and no matter how long you try to explain it to them, they&#8217;ll still only care about having a <a href="http://www.funnyjunk.com/funny_pictures/112243/Web+design+from+Hell/">picture of their dog on their web site</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fusioncube.net/index.php/i-could-care-less-what-you-say/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Agent Oriented Software</title>
		<link>http://www.fusioncube.net/index.php/agent-oriented-software</link>
		<comments>http://www.fusioncube.net/index.php/agent-oriented-software#comments</comments>
		<pubDate>Tue, 26 Jan 2010 21:36:58 +0000</pubDate>
		<dc:creator>Steve Brownlee</dc:creator>
				<category><![CDATA[agent oriented software]]></category>
		<category><![CDATA[design patterns]]></category>

		<guid isPermaLink="false">http://www.fusioncube.net/?p=692</guid>
		<description><![CDATA[I&#8217;ve been obsessed lately with reading about Agent Oriented Programming (AOP). I&#8217;m fascinated about the concept of making objects autonomous and capable of responding to environmental changes, rather than predefining what they will and will not do (as opposed to what they can and cannot do). It is interesting, for me, to note that AOP [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been obsessed lately with reading about Agent Oriented Programming (AOP).  I&#8217;m fascinated about the concept of making objects autonomous and capable of responding to environmental changes, rather than predefining what they will and will not do (as opposed to what they can and cannot do).</p>
<p>It is interesting, for me, to note that AOP and Service Oriented Architectures (SOA) started to gain momentum around the same time, and yet the interest, and advancements, in SOA quickly outdistanced those for AOP.</p>
<p>In my opinion, this is because the practical applications for AOP are minimal, while the concepts of SOA can quickly and easily be grasped and implemented in many business environments.</p>
<p>I can&#8217;t really find any white papers from someone who&#8217;s actually implemented a project with this kind of architecture, so it all seems stalled in the theoretical phase still.  Of course, I can&#8217;t think of a project that I&#8217;m working where we could use this.  </p>
<p>I still find it fascinating, though.</p>
<p><a href="http://c2.com/cgi/wiki?WhatIsAnAgent">What Is An Agent?</a><br />
<a href="http://c2.com/cgi/wiki?PropertiesOfAgents">Properties of Agents</a><br />
<a href="http://www.agentlab.de/aose.html">Agent Oriented Software Engineering</a><br />
<a href="http://www.msci.memphis.edu/~franklin/AgentProg.html">A Taxonomy for Autonomous Agents</a><br />
<a href="http://www.marcush.net/IRS/Jam/Jam-man-01Nov01-draft.htm">Jam! Agent Architecture</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.fusioncube.net/index.php/agent-oriented-software/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Cairngorm: Abstract Events Updated</title>
		<link>http://www.fusioncube.net/index.php/cairngorm-abstract-events-updated</link>
		<comments>http://www.fusioncube.net/index.php/cairngorm-abstract-events-updated#comments</comments>
		<pubDate>Wed, 03 Jun 2009 13:19:30 +0000</pubDate>
		<dc:creator>Steve Brownlee</dc:creator>
				<category><![CDATA[cairngorm]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[flex]]></category>

		<guid isPermaLink="false">http://www.fusioncube.net/?p=560</guid>
		<description><![CDATA[Purpose The intended purpose for the AbstractEvent class in Cairngorm was three-fold: Reduce the number of files needed to manage business events by organizing Events into domains Implement a callback feature so that a view can specify another action to perform upon the successful completion of an event Make each domain event class as lightweight [...]]]></description>
			<content:encoded><![CDATA[<h1>Purpose</h1>
<p>The intended purpose for the AbstractEvent class in Cairngorm was three-fold:</p>
<ol>
<li>Reduce the number of files needed to manage business events by organizing Events into domains</li>
<li>Implement a callback feature so that a view can specify another action to perform upon the successful completion of an event</li>
<li>Make each domain event class as lightweight as possible</li>
</ol>
<h1>Related Posts</h1>
<p><a href="http://www.fusioncube.net/index.php/cairngorm-abstract-events-updated">Abstract Commands</a> | <a href="http://www.fusioncube.net/index.php/abstractdelegate-for-cairngorm">Abstract Delegates</a></p>
<h1>Concept</h1>
<p>To accomplish these goals, each domain event (e.g. ProjectEvent, PaymentEvent, etc.) would be polymorphic (kinda) in that there is no longer just one identifier designated with the EVENT_ID constant. In addition, I wanted to abstract as much functionality and classification as possible into a common class that each domain event would extend.<br />
<img src="http://www.fusioncube.net/wp-content/uploads/2009/06/abstract_event.png" alt="abstract_event" title="abstract_event" width="344" height="78" class="alignnone size-full wp-image-564" /></p>
<h1>Lightweight, Polymorphic Event Class</h1>
<p>Here&#8217;s an example of a domain event.  It has three public identifiers &#8211; CREATE_PROJECT, LOAD_PROJECTS, DEACTIVATE_PROJECT- and has no logic other than to pass its constructor&#8217;s arguments to AbstractEvent.</p>
<h3>ProjectEvent.as</h3>
<pre class="code"><code>package business.events
{
   import com.adobe.cairngorm.control.CairngormEvent;

   public class ProjectEvent extends AbstractEvent
   {
      public static const CREATE_PROJECT:String = "createProject";
      public static const LOAD_PROJECTS:String = "getProjects";
      public static const DEACTIVATE_PROJECT:String = "deactivateProject";

      public function ProjectEvent(type:String, data:Object = null, callbacks:Array=null)
      {
         super(type, data, callback);
      }
   }
}</code></pre>
<h1>AbstractEvent Class</h1>
<p>The AbstractEvent class itself isn&#8217;t much more complicated at all.  It simply has three public variables to hold the type of the event, an object containing key/value pairs for the data, and the reference to the callback function in the view (if specified).</p>
<h3>AbstractEvent.as</h3>
<pre class="code"><code>package business.events
{
   import com.adobe.cairngorm.control.CairngormEvent;

   public class AbstractEvent extends CairngormEvent
   {
      public var callbacks:Array = null;

      public function AbstractEvent(type:String, data:Object = null, callbacks:Array=[])
      {
         super(type);

         this.data = data;
         this.callbacks = callbacks;
      }
   }
}</code></pre>
<h1>Example View &#8211; Projects</h1>
<p>Here&#8217;s some snippets of code from my project view. One piece of functionality is for a user to disable a selected project from a list in an AdvancedDataGrid. When the user clicks on the &#8220;Disable Project&#8221; button, the btnDeactivateProject_Click() function fires and creates a new Project event in which the loadProjects() function is specified as the callback function.</p>
<h3>Projects.mxml</h3>
<pre class="code"><code>private function btnDeactivateProject_Click(e:Event):void
{
   var thisProject:Project = gridProjects.selectedItem as Project;
   new ProjectEvent(ProjectEvent.DEACTIVATE_PROJECT,
            {project:thisProject},
            [loadProjects]).dispatch();
}

public function loadProjects():void
{
   new ProjectEvent(ProjectEvent.LOAD_PROJECTS).dispatch();
}

&lt;mx:Button id="btnDeactivateProject"
	click="btnDeactivateProject_Click(event)"
	x="10" y="393"
	label="Deactivate Project"/&gt;</code></pre>
<h1>Mapping Events to Commands</h1>
<p>Your controller logic doesn&#8217;t change.  The only difference is that you&#8217;re using one domain event, with specified identities, mapped to different Commands.</p>
<h3>Controller.as</h3>
<pre class="code"><code>package business
{
   import business.commands.*;
   import business.events.*;
   import com.adobe.cairngorm.control.FrontController;

   public class Controller extends FrontController
   {
      public function Controller()
      {
         super();
         addCommand(ProjectEvent.LOAD_PROJECTS, LoadProjectsCommand);
         addCommand(ProjectEvent.CREATE_PROJECT, CreateProjectCommand);
         addCommand(ProjectEvent.DEACTIVATE_PROJECT, DeactivateProjectCommand);
      }
   }
}</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.fusioncube.net/index.php/cairngorm-abstract-events-updated/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Cairngorm: Abstract Commands Updated</title>
		<link>http://www.fusioncube.net/index.php/cairngorm-abstract-commands-updated</link>
		<comments>http://www.fusioncube.net/index.php/cairngorm-abstract-commands-updated#comments</comments>
		<pubDate>Wed, 03 Jun 2009 13:19:10 +0000</pubDate>
		<dc:creator>Steve Brownlee</dc:creator>
				<category><![CDATA[cairngorm]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[flex]]></category>

		<guid isPermaLink="false">http://www.fusioncube.net/?p=543</guid>
		<description><![CDATA[Purpose The intended purpose for the AbstractCommand class in Cairngorm is three-fold: Further implementation of a callback feature &#8211; in conjunction with the AbstractEvent &#8211; so that a view can specify other actions to perform upon the successful completion of business event Create a Responder object for the Delegate to use Make each Command class [...]]]></description>
			<content:encoded><![CDATA[<h1>Purpose</h1>
<p>The intended purpose for the AbstractCommand class in Cairngorm is three-fold:</p>
<ol>
<li>Further implementation of a callback feature &#8211; in conjunction with the AbstractEvent &#8211; so that a view can specify other actions to perform upon the successful completion of business event</li>
<li>Create a Responder object for the Delegate to use</li>
<li>Make each Command class as lightweight as possible</li>
</ol>
<h1>Related Posts</h1>
<p><a href="http://www.fusioncube.net/index.php/cairngorm-patterns-batch-commands">Batch Commands</a> | <a href="http://www.fusioncube.net/index.php/cairngorm-abstract-events-updated">Abstract Events</a> | <a href="http://www.fusioncube.net/index.php/abstractdelegate-for-cairngorm">Abstract Delegates</a></p>
<h1>Concept</h1>
<p><img src="http://www.fusioncube.net/wp-content/uploads/2009/06/abstract_command.png" alt="abstract_command" title="abstract_command" width="300" height="248" class="alignnone size-full wp-image-547" /></p>
<h1>Standard, Responseful Command</h1>
<p>Below is an example Command in my system, it extends AbstractCommand which in turn implements the ICustomCommand interface. To make the Command responseful, an array of functions is passed from the Event to the Command, which will execute them upon success (see more below).  Here&#8217;s an example call:</p>
<pre class="code"><code>new EmployeeEvent(EmployeeEvent.GET_DETAILS,
         {employee_id:params.empID},
         [showEmployeeDetails, updateEmployeeGraph])</code></pre>
<p>To implement a very basic command, it is only required to set the delegate property to a new instance of the appropriate Delegate class, and then invoke the needed method.  The AbstractCommand will automatically create a new Responder object and assign it to the delegate.</p>
<h3>LoadProjectCommand.as</h3>
<pre class="code"><code>public class LoadProjectCommand extends AbstractCommand
{
   private var _model:ModelLocator = ModelLocator.getInstance();

   override public function execute():void
   {
      delegate = new ProjectDelegate();
      (delegate as ProjectDelegate).loadProject(invoker.data);
   }

   override public function commandSuccess(event:Event):void
   {
      if (event.result.success)
      {
         _model.project = (event as ResultEvent).result.data;
         notifyInvoker();
      }
   }
}
}</code></pre>
<p>The invoker object is a reference to the original Event that was called, and to get it assigned as a property of the Command, I extended the FrontController class so that it is assigned before the Command is executed.</p>
<pre class="code"><code>protected function executeAbstractCommand(event:AbstractEvent):void
{
   var commandRef:Class = getCommand(event.type);
   var commandToExecute:ICustomCommand = new commandRef();

   commandToExecute.invoker = event;
   commandToExecute.execute();
}</code></pre>
<h1>AbstractCommand Class</h1>
<p>This class is straightforward and handles the tedious aspects of creating a Command.  The notifyInvoker() method simply loops through the array of callback functions &#8211; if they exist &#8211; and runs them.</p>
<h3>AbstractCommand.as</h3>
<pre class="code"><code>public class AbstractCommand
{
   private var _callbacks:Array = null;
   private var _invoker:AbstractEvent = null;
   private var _delegate:AbstractDelegate = null;

   public function AbstractCommand() { }
   public function execute():void { }
   public function commandSuccess(event:Event):void { }
   public function commandFault(event:Event):void { }

   public function set delegate(d:*):void
   {
      _delegate = d;
      _delegate.setResponder(new Responder(commandSuccess, commandFault));
   }

   public function get delegate():*
   {
      return _delegate;
   }

   public function set invoker(e:AbstractEvent):void
   {
      _invoker = e;
      if (e.callbacks != null) _callbacks = e.callbacks;
   }

   public function get invoker():AbstractEvent
   {
      return _invoker;
   }

   public function notifyInvoker(info:Object = null):void
   {
      if (_callbacks != null)
      {
         for (var i:uint = 0; i &lt; _callbacks.length; i++)
         {
            var callback:Function = _callbacks[i];
           (info != null) ? callback.call(this, info) : callback.call(this);
         }
      }
   }
}</code></pre>
<h1>ICustomCommand Interface</h1>
<h3>ICustomCommand.as</h3>
<pre class="code"><code>package business.commands
{
   import business.events.AbstractEvent;
   import flash.events.Event;

   public interface ICustomCommand
   {
      function commandSuccess(event:Event):void;
      function commandFault(event:Event):void;
      function execute():void;
      function set invoker(event:AbstractEvent):void;
      function set delegate(delegate:*):void;
   }
}</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.fusioncube.net/index.php/cairngorm-abstract-commands-updated/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Cairngorm Patterns: Batch Commands</title>
		<link>http://www.fusioncube.net/index.php/cairngorm-patterns-batch-commands</link>
		<comments>http://www.fusioncube.net/index.php/cairngorm-patterns-batch-commands#comments</comments>
		<pubDate>Tue, 31 Mar 2009 14:19:45 +0000</pubDate>
		<dc:creator>Steve Brownlee</dc:creator>
				<category><![CDATA[cairngorm]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[flex]]></category>

		<guid isPermaLink="false">http://www.fusioncube.net/?p=451</guid>
		<description><![CDATA[Related Posts Abstract Commands Basic Cairngorm Commands In the base implementation of the Cairngorm micro-architecture, events and commands are mapped on a 1-1 basis. For every invoker (event) you have to specify one command in your controller. public function Controller() { super(); addCommand(TeammateEvent.LOAD_TEAMMATES, LoadTeammatesCommand); addCommand(EffortEvent.LOAD_TYPES, LoadEffortTypesCommand); addCommand(ProjectEvent.LOAD_PROJECTS, LoadProjectsCommand); addCommand(TeammateEvent.LOAD_TEAMMATE_ROLES, LoadTeammateRolesCommand); ... } For most cases, [...]]]></description>
			<content:encoded><![CDATA[<h1>Related Posts</h1>
<p><a href="http://www.fusioncube.net/index.php/cairngorm-abstract-commands-updated">Abstract Commands</a></p>
<h1>Basic Cairngorm Commands</h1>
<p>In the base implementation of the Cairngorm micro-architecture, events and commands are mapped on a 1-1 basis.  For every invoker (event) you have to specify one command in your controller.</p>
<pre class="code"><code>public function Controller()
{
   super();
   addCommand(TeammateEvent.LOAD_TEAMMATES, LoadTeammatesCommand);
   addCommand(EffortEvent.LOAD_TYPES, LoadEffortTypesCommand);
   addCommand(ProjectEvent.LOAD_PROJECTS, LoadProjectsCommand);
   addCommand(TeammateEvent.LOAD_TEAMMATE_ROLES, LoadTeammateRolesCommand);
   ...
}</code></pre>
<p>For most cases, this is perfectly fine, but in a data-heavy model, such as the one being built for my current application, I need to initialize the application and fire off many individual events in order to load my model with base data.</p>
<pre class="code"><code>// Load all teammates in the database for display in the reports tab
new TeammateEvent(TeammateEvent.LOAD_TEAMMATES).dispatch();

// Load all effort types
new EffortEvent(EffortEvent.LOAD_TYPES).dispatch();

// Load all projects
new ProjectEvent(ProjectEvent.LOAD_PROJECTS).dispatch();

// Load all roles
new TeammateEvent(TeammateEvent.LOAD_TEAMMATE_ROLES).dispatch();

...</code></pre>
<h1>Batch Commands</h1>
<p>In order to avoid having to dispatch <em>n</em> events for <em>n</em> commands to be executed, I would rather map 1 event to <em>n</em> commands and have them fired off in sequence.  Then, if I need a batch of commands to fire, I only need to dispatch one event, instead of the 4 I used in the example above.</p>
<pre class="code"><code>new ApplicationEvent(ApplicationEvent.LOAD_MODEL).dispatch();</code></pre>
<p>Unfortunately, Cairngorm does not allow this, so I had to extend the basic architecture.  I created a addCommands() function that maps a single event to multiple commands as an array.</p>
<pre class="code"><code>public class Controller extends ExtendedFrontController
{
   public function Controller()
   {
      addCommands(ApplicationEvent.LOAD_MODEL, [LoadTeammatesCommand,
                                LoadEffortTypesCommand,
                                LoadProjectsCommand,
                                LoadTeammateRolesCommand,
                                ...]);
   }
}</code></pre>
<h1>Extended Controller Class</h1>
<p>Here&#8217;s the code that I&#8217;ve come up with so far.  This is working fine, but there still some things I plan on implementing in the future.</p>
<h3>ExtendedFrontController.as</h3>
<pre class="code"><code>public class ExtendedFrontController extends FrontController
{
   public function ExtendedFrontController()
   {
      super();
   }

   public function addCommands(commandName:String, commandRefs:Array, useWeakReference:Boolean = true):void
   {
      if(commands[ commandName ] != null)
      {
         throw new CairngormError( CairngormMessageCodes.COMMAND_ALREADY_REGISTERED, commandName );
      }

      if (commandRefs == null)
      {
         throw new Error("The commandRefs argument to addCommands() is null");
      }

      commands[commandName] = commandRefs;

      for (var priority:uint = 0; priority &lt; commandRefs.length; priority++)
      {
         CairngormEventDispatcher.getInstance().addEventListener(commandName, executeCommands, false, priority, useWeakReference);
      }
   }

   protected function executeCommands(event:AbstractEvent):void
   {
      var commandsToInitialise:Array = getCommands(event.type);
      var commandRef:Class;

      for (var i:uint = 0; i &lt; commandsToInitialise.length; i++)
      {
         commandRef = commandsToInitialise[i];
         var commandToExecute:ICustomCommand = new commandRef();
         commandToExecute.execute(event);
      }
   }

   protected function getCommands(commandName:String):Array
   {
      var commands:Array = commands[commandName];

      if ( commands == null )
         throw new CairngormError( CairngormMessageCodes.COMMAND_NOT_FOUND, commandName );

      return commands;
   }
}</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.fusioncube.net/index.php/cairngorm-patterns-batch-commands/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>A Better, Stronger Flex Architecture</title>
		<link>http://www.fusioncube.net/index.php/a-better-stronger-flex-architecture</link>
		<comments>http://www.fusioncube.net/index.php/a-better-stronger-flex-architecture#comments</comments>
		<pubDate>Tue, 24 Mar 2009 02:25:39 +0000</pubDate>
		<dc:creator>Steve Brownlee</dc:creator>
				<category><![CDATA[cairngorm]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[flex]]></category>

		<guid isPermaLink="false">http://www.fusioncube.net/?p=422</guid>
		<description><![CDATA[Cairngorm++ Call me a junkie, that&#8217;s fine, but this stuff works. I&#8217;ve said many times in the past that the whole purpose of using design patterns, code frameworks, and application architectures should be to reduce the code I write (as time progresses), make an application easier to extend, and reduce the cost of turnover. After [...]]]></description>
			<content:encoded><![CDATA[<h1>Cairngorm++</h1>
<p>Call me a junkie, that&#8217;s fine, but this stuff works.  I&#8217;ve said many times in the past that the whole purpose of using design patterns, code frameworks, and application architectures should be to reduce the code I write (as time progresses), make an application easier to extend, and reduce the cost of turnover.</p>
<p>After quickly learning what the <a href="http://opensource.adobe.com/wiki/display/cairngorm/">Cairngorm architecture</a> had to offer, I noticed several gaps that needed to be filled.  One of which was the inordinate amount of files that are created using the base patterns (which I alleviated with my abstract classes for <a href="http://www.fusioncube.net/index.php/cairngorm-patterns-abstract-events">Event</a>, <a href="http://www.fusioncube.net/index.php/cairngorm-patterns-abstract-commands">Command</a>, and <a href="http://www.fusioncube.net/index.php/abstractdelegate-for-cairngorm">Delegate</a>).  Another gap is that it doesn&#8217;t have a view mediator.  That&#8217;s the one feature from the <a href="http://puremvc.org/component/option,com_wrapper/Itemid,144/">PureMVC framework</a> that I actually was a huge fan of.</p>
<h1>Mediators</h1>
<p>You see, PureMVC uses a <a href="http://en.wikipedia.org/wiki/Mediator_pattern">Mediator pattern</a> in order to provide a mechanism by which views could interact with the business logic, as well as with each other, while remaining ignorant of the man behind the curtain.  Keeping the views decoupled from the model is good &#8211; especially with my apps &#8211; because subtle changes to the data model happen often, and while a good part of that is handled in the business logic, it often bubbles up to the UI model as well.</p>
<h1>I am a Command, I am an Island</h1>
<p>Another value feature that other frameworks have is that ability for a View &#8211; via a Mediator &#8211; to actually know if a Command was successful or not.  Gasp!  With the base Cairngorm implementation, the only way to perform an action on success of a Command was in the Command itself.  Very bad, otherwise you end up with situations that call for <strong>SaveProjectAndReloadModelCommand</strong> in which you do one action and then immediately call another Command, and <strong>SaveProjectWithNoModelReloadCommand</strong> for when you don&#8217;t need to do the second Command.</p>
<p>A Command should be as insular as possible.  It should never directly call another Command.</p>
<h1>Responseful Commands</h1>
<p>My way around this was to implement a function callback feature in the <a href="http://www.fusioncube.net/index.php/cairngorm-patterns-abstract-events">Event</a> and <a href="http://www.fusioncube.net/index.php/cairngorm-patterns-abstract-commands">Command</a> abstract classes.  </p>
<p><img src="http://www.fusioncube.net/wp-content/uploads/2009/03/abstract.png" alt="abstract" title="abstract" width="194" height="178" class="alignnone size-full wp-image-427" /></p>
<p>When an Event is dispatched from a View, the name of a local function is passed as an argument.  The Command consumes this function reference and then runs it if the execution was successful.</p>
<h1>Tested in the Field</h1>
<p>Sure, theory is fine, but how does all this work when actually writing a Flex app?  Well, I put that to the test just the other day.  An app I&#8217;m working needed a significant enhancement and change.  After changing the database model, I was able to crank out the business logic, and three views in Flex in which users could create new items, deactivate/activate them, and a few other doo-dads in just under 40 minutes.</p>
<h1>Conclusion</h1>
<p>Don&#8217;t be afraid to enhance a framework or code architecture with your own ideas.  Trust yourself and your ideas because you&#8217;re smart, too.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fusioncube.net/index.php/a-better-stronger-flex-architecture/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Cairngorm Patterns: Abstract Commands</title>
		<link>http://www.fusioncube.net/index.php/cairngorm-patterns-abstract-commands</link>
		<comments>http://www.fusioncube.net/index.php/cairngorm-patterns-abstract-commands#comments</comments>
		<pubDate>Wed, 18 Mar 2009 15:21:06 +0000</pubDate>
		<dc:creator>Steve Brownlee</dc:creator>
				<category><![CDATA[design patterns]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[frameworks]]></category>

		<guid isPermaLink="false">http://www.fusioncube.net/?p=377</guid>
		<description><![CDATA[Purpose My intended purpose for the AbstractCommand class in Cairngorm was two-fold: Implement a callback feature so that a view can specify another action to perform upon the successful completion of an event Make each Command class as lightweight as possible Related Posts Batch Commands &#124; Abstract Events &#124; Abstract Delegates Concept Standard, Responseful Command [...]]]></description>
			<content:encoded><![CDATA[<h1>Purpose</h1>
<p>My intended purpose for the AbstractCommand class in Cairngorm was two-fold:</p>
<ol>
<li>Implement a callback feature so that a view can specify another action to perform upon the successful completion of an event</li>
<li>Make each Command class as lightweight as possible</li>
</ol>
<h1>Related Posts</h1>
<p><a href="http://www.fusioncube.net/index.php/cairngorm-patterns-batch-commands">Batch Commands</a> | <a href="http://www.fusioncube.net/index.php/cairngorm-patterns-abstract-events">Abstract Events</a> | <a href="http://www.fusioncube.net/index.php/abstractdelegate-for-cairngorm">Abstract Delegates</a></p>
<h1>Concept</h1>
<p><img style="margin:30px 0 30px 0;" src="http://www.fusioncube.net/wp-content/uploads/2009/03/davita_cairngorm_command.png" alt="Abstract Command and Interface" title="Abstract Command and Interface" width="311" height="222" class="alignnone size-full wp-image-388" /></p>
<h1>Standard, Responseful Command</h1>
<p>Here&#8217;s an example Command in my system, it extends AbstractCommand and implements the ICustomCommand interface &#8211; which simply enforces a commandSuccess() and commandFault() method be present.</p>
<p>When the execute() method is invoked, the callback function property of the <a href="http://www.fusioncube.net/index.php/cairngorm-patterns-abstract-events">domain event</a> is assigned by calling the setCallbackFunction() of the AbstractCommand, then the standard process of instantiating the proper delegate happens.</p>
<p>Now that the Command has a reference to the callback function (if it exists), in the commandSuccess() method, we simply call the AbstractCommand&#8217;s notifyCaller() method which executes that function.</p>
<h3>DeactivateProjectCommand.as</h3>
<pre class="code"><code>package business.commands
{
   public class DeactivateProjectCommand extends AbstractCommand implements ICustomCommand
   {
      private var _model:ModelLocator = ModelLocator.getInstance();

      public function execute(event:CairngormEvent):void
      {
         setCallbackFunction((event as ProjectEvent).callbackFunction);

         var delegate:ProjectDelegate = new ProjectDelegate();
         delegate.setResponder(new Responder(commandSuccess, commandFault));
         delegate.deactivate((event as ProjectEvent).eventData);
      }

      public function commandSuccess(event:ResultEvent):void
      {
         if (event.result.success)
         {
            notifyCaller(event.result.data.project as Project);
         }
      }

      public function commandFault(event:FaultEvent):void { }
   }
}</code></pre>
<h1>AbstractCommand Class</h1>
<p>This class is straightforward and simple.  It simply contains the setCallbackFunction() and notifyCaller() methods with a private class member _callback.</p>
<h3>AbstractCommand.as</h3>
<pre class="code"><code>package business.commands
{
   public class AbstractCommand
   {
      private var _callback:Function = null;

      public function setCallbackFunction(value:Function):void
      {
         if (value != null) _callback = value;
      }

      public function notifyCaller(info:Object = null):void
      {
         if (_callback != null)
         {
            if (info != null)
            {
               _callback.call(this, info);
            } else {
               _callback.call(this);
            }
         }
      }
   }
}</code></pre>
<h1>ICustomCommand Interface</h1>
<p>This interface simply enforces the implementation of the commandSuccess() and commandFault() methods.</p>
<h3>ICustomCommand.as</h3>
<pre class="code"><code>package business.commands
{
   import com.adobe.cairngorm.commands.ICommand;
   import mx.rpc.events.FaultEvent;
   import mx.rpc.events.ResultEvent;

   public interface ICustomCommand extends ICommand
   {
      function commandSuccess(event:ResultEvent):void;
      function commandFault(event:FaultEvent):void;
   }
}</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.fusioncube.net/index.php/cairngorm-patterns-abstract-commands/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Cairngorm Patterns: Abstract Events</title>
		<link>http://www.fusioncube.net/index.php/cairngorm-patterns-abstract-events</link>
		<comments>http://www.fusioncube.net/index.php/cairngorm-patterns-abstract-events#comments</comments>
		<pubDate>Wed, 18 Mar 2009 15:20:57 +0000</pubDate>
		<dc:creator>Steve Brownlee</dc:creator>
				<category><![CDATA[design patterns]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[frameworks]]></category>

		<guid isPermaLink="false">http://www.fusioncube.net/?p=354</guid>
		<description><![CDATA[Purpose My intended purpose for the AbstractEvent class in Cairngorm was three-fold: Reduce the number of files needed to manage business events by organizing Events into domains Implement a callback feature so that a view can specify another action to perform upon the successful completion of an event Make each domain event class as lightweight [...]]]></description>
			<content:encoded><![CDATA[<h1>Purpose</h1>
<p>My intended purpose for the AbstractEvent class in Cairngorm was three-fold:</p>
<ol>
<li>Reduce the number of files needed to manage business events by organizing Events into domains</li>
<li>Implement a callback feature so that a view can specify another action to perform upon the successful completion of an event</li>
<li>Make each domain event class as lightweight as possible</li>
</ol>
<h1>Related Posts</h1>
<p><a href="http://www.fusioncube.net/index.php/cairngorm-patterns-abstract-commands">Abstract Commands</a> | <a href="http://www.fusioncube.net/index.php/abstractdelegate-for-cairngorm">Abstract Delegates</a></p>
<h1>Concept</h1>
<p>To accomplish my goals, each domain event (e.g. ProjectEvent, PaymentEvent, etc.) would be polymorphic (kinda) in that there is no longer just one identifier designated with the EVENT_ID constant. In addition, I wanted to abstract as much functionality and classification as possible into a common class that each domain event would extend.<br />
<img style="margin:30px 0 0 0;" src="http://www.fusioncube.net/wp-content/uploads/2009/03/davita_cairngorm_event.png" alt="Abstract Event" title="Abstract Event" width="369" height="78" class="alignnone size-full wp-image-362" /></p>
<h1>Lightweight, Polymorphic Event Class</h1>
<p>Here&#8217;s an example of a domain event.  It has three public identifiers &#8211; CREATE_PROJECT, LOAD_PROJECTS, DEACTIVATE_PROJECT- and has no logic other than to pass its constructor&#8217;s arguments to AbstractEvent.</p>
<h3>ProjectEvent.as</h3>
<pre class="code"><code>package business.events
{
   import com.adobe.cairngorm.control.CairngormEvent;

   public class ProjectEvent extends AbstractEvent
   {
      public static const CREATE_PROJECT:String = "createProject";
      public static const LOAD_PROJECTS:String = "getProjects";
      public static const DEACTIVATE_PROJECT:String = "deactivateProject";

      public function ProjectEvent(type:String, data:Object = null, callback:Function = null)
      {
         super(type, data, callback);
      }
   }
}</code></pre>
<h1>AbstractEvent Class</h1>
<p>The AbstractEvent class itself isn&#8217;t much more complicated at all.  It simply has three public variables to hold the type of the event, an object containing key/value pairs for the data, and the reference to the callback function in the view (if specified).</p>
<h3>AbstractEvent.as</h3>
<pre class="code"><code>package business.events
{
   import com.adobe.cairngorm.control.CairngormEvent;

   public class AbstractEvent extends CairngormEvent
   {
      public var eventType:String = "";
      public var eventData:Object = new Object();
      public var callbackFunction:Function = null;

      public function AbstractEvent(type:String, data:Object = null, callback:Function = null)
      {
         super(type);
         eventType = type;
         eventData = data;
         callbackFunction = callback;
      }
   }
}</code></pre>
<h1>Example View &#8211; Projects</h1>
<p>Here&#8217;s some snippets of code from my project view. One piece of functionality is for a user to disable a selected project from a list in an AdvancedDataGrid. When the user clicks on the &#8220;Disable Project&#8221; button, the btnDeactivateProject_Click() function fires and creates a new Project event in which the loadProjects() function is specified as the callback function.</p>
<h3>Projects.mxml</h3>
<pre class="code"><code>private function btnDeactivateProject_Click(e:Event):void
{
   var p:Project = gridProjects.selectedItem as Project;
   var event:ProjectEvent = new ProjectEvent(
                                  ProjectEvent.DEACTIVATE_PROJECT,
                                  {project:p},
                                  loadProjects);
   event.dispatch();
}

public function loadProjects():void
{
   var projectEvent:ProjectEvent = new ProjectEvent(ProjectEvent.LOAD_PROJECTS);
   projectEvent.dispatch();
}

&lt;mx:Button id="btnDeactivateProject"
	click="btnDeactivateProject_Click(event)"
	x="10" y="393"
	label="Deactivate Project"/&gt;</code></pre>
<h1>Mapping Events to Commands</h1>
<p>Your controller logic doesn&#8217;t change.  The only difference is that you&#8217;re using one domain event, with specified identities, mapped to difference Commands.</p>
<h3>Controller.as</h3>
<pre class="code"><code>package business
{
   import business.commands.*;
   import business.events.*;
   import com.adobe.cairngorm.control.FrontController;

   public class Controller extends FrontController
   {
      public function Controller()
      {
         super();
         addCommand(ProjectEvent.LOAD_PROJECTS, LoadProjectsCommand);
         addCommand(ProjectEvent.CREATE_PROJECT, CreateProjectCommand);
         addCommand(ProjectEvent.DEACTIVATE_PROJECT, DeactivateProjectCommand);
      }
   }
}</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.fusioncube.net/index.php/cairngorm-patterns-abstract-events/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Cairngorm Patterns: Abstract Delegate</title>
		<link>http://www.fusioncube.net/index.php/abstractdelegate-for-cairngorm</link>
		<comments>http://www.fusioncube.net/index.php/abstractdelegate-for-cairngorm#comments</comments>
		<pubDate>Thu, 12 Mar 2009 22:26:49 +0000</pubDate>
		<dc:creator>Steve Brownlee</dc:creator>
				<category><![CDATA[design patterns]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[frameworks]]></category>

		<guid isPermaLink="false">http://www.fusioncube.net/?p=345</guid>
		<description><![CDATA[Purpose My intended purpose for the AbstractDelegate class in Cairngorm was two-fold: Reduce the number of files needed to manage business events by organizing Delegates into domains Make each domain Delegate class as lightweight as possible Related Posts Abstract Commands &#124; Abstract Events Concept Lightweight Delegate By extending the AbstractDelegate class, each domain Delegate created [...]]]></description>
			<content:encoded><![CDATA[<h1>Purpose</h1>
<p>My intended purpose for the AbstractDelegate class in Cairngorm was two-fold:</p>
<ol>
<li>Reduce the number of files needed to manage business events by organizing Delegates into domains</li>
<li>Make each domain Delegate class as lightweight as possible</li>
</ol>
<h1>Related Posts</h1>
<p><a href="http://www.fusioncube.net/index.php/cairngorm-patterns-abstract-commands">Abstract Commands</a> | <a href="http://www.fusioncube.net/index.php/cairngorm-patterns-abstract-events">Abstract Events</a></p>
<h1>Concept</h1>
<p><img style="margin:30px 0 30px 0;" src="http://www.fusioncube.net/wp-content/uploads/2009/03/davita_cairngorm_delegate.png" alt="Abstract Delegate" title="Abstract Delegate" width="102" height="188" class="alignnone size-full wp-image-393" /></p>
<h1>Lightweight Delegate</h1>
<p>By extending the AbstractDelegate class, each domain Delegate created by a developer become absurdly lightweight and simple. Basically, it become a series of methods mapped to remote procedure call names.</p>
<h3>ProjectDelegate.as</h3>
<pre class="code"><code>package business.delegates
{
   public class ProjectDelegate extends AbstractDelegate
   {
      public function loadProjects():void
      {
         send("getProjects", {});
      }

      public function deactivate(eventData:Object):void
      {
         send("deactivateProject", eventData);
      }

      public function createProject(eventData:Object):void
      {
         send("createProject", eventData);
      }
   }
}</code></pre>
<h1>AbstractDelegate Class</h1>
<p>The the AbstractDelete class will take care of holding the reference to the application&#8217;s data model, and constructing the final RPC with the designated Responder attached.</p>
<h3>AbstractDelegate.as</h3>
<pre class="code"><code>package business.delegates
{
   import business.RemoteFactoryLocator;
   import flash.utils.getQualifiedClassName;
   import mx.rpc.IResponder;

   public class AbstractDelegate
   {
      private var _responder:IResponder;
      private var _remoteService:RemoteFactoryLocator = RemoteFactoryLocator.getInstance();

      public function AbstractDelegate()
      {
         if(flash.utils.getQualifiedClassName(this) == "business.delegates::AbstractDelegate")
         {
            throw new Error("ClassInstantiationException: Cannot create an instance of an abstract class.");
         }
      }

      public function setResponder(responder:IResponder):void
      {
         _responder = responder;
      }

      public function send(eventName:String, eventData:Object):void
      {
         _remoteService.send(eventName, eventData, _responder);
      }
   }
}</code></pre>
<p>So now all of my delegates extend the AbstractDelegate which allows us to write less code for all of these stinking delegates for our application.</p>
<p>The only ramification is that the Commands (see <a href="http://www.fusioncube.net/index.php/cairngorm-patterns-abstract-commands">Abstract Command post</a> for example) now have to call the setResponder() method on each delegate.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fusioncube.net/index.php/abstractdelegate-for-cairngorm/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>ColdFusion Object Creation &#8211; More</title>
		<link>http://www.fusioncube.net/index.php/coldfusion-object-creation-more</link>
		<comments>http://www.fusioncube.net/index.php/coldfusion-object-creation-more#comments</comments>
		<pubDate>Fri, 13 Feb 2009 04:51:52 +0000</pubDate>
		<dc:creator>Steve Brownlee</dc:creator>
				<category><![CDATA[AOP]]></category>
		<category><![CDATA[coldfusion]]></category>
		<category><![CDATA[coldspring]]></category>
		<category><![CDATA[design patterns]]></category>

		<guid isPermaLink="false">http://www.fusioncube.net/?p=319</guid>
		<description><![CDATA[Following up on my original post about ColdFusion performance hits on creating objects &#8211; it was suggested that I return an array of typed structures instead of an array of components. I already had a nice AOP class for each of these scenarios, so all I had to do was add the __type__ column to [...]]]></description>
			<content:encoded><![CDATA[<p>Following up on my <a href="http://www.fusioncube.net/index.php/coldfusion-object-creation-performance-hit">original post about ColdFusion performance hits on creating objects</a> &#8211; it was suggested that I return an array of typed structures instead of an array of components.</p>
<p>I already had a nice AOP class for each of these scenarios, so all I had to do was add the __type__ column to the array of structures, and I was good.  The test results below seem logical&#8230; except for the first set of testing 50 rows.  Converting the query results into an array of structs using a simple function call to another component was actually SLOWER than using AOP or converting to DTOs.</p>
<p>Besides that anomaly, the performance hit for using ColdSpring AOP proxies and using DTOs is clearly visible as you add more data.</p>
<p><img src="http://www.fusioncube.net/wp-content/uploads/2009/02/50rows.png" alt="50rows" title="50rows" width="406" height="223" class="alignnone size-full wp-image-320" /><br />
<br/><br/><br />
<img src="http://www.fusioncube.net/wp-content/uploads/2009/02/250rows.png" alt="250rows" title="250rows" width="412" height="221" class="alignnone size-full wp-image-321" /><br />
<br/><br/><br />
<img src="http://www.fusioncube.net/wp-content/uploads/2009/02/500rows.png" alt="500rows" title="500rows" width="420" height="225" class="alignnone size-full wp-image-322" /><br />
<br/><br/><br />
<img src="http://www.fusioncube.net/wp-content/uploads/2009/02/1000rows.png" alt="1000rows" title="1000rows" width="416" height="229" class="alignnone size-full wp-image-323" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.fusioncube.net/index.php/coldfusion-object-creation-more/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

