<?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>CuriousFind &#187; Cairngorm</title>
	<atom:link href="http://www.curiousfind.com/blog/category/flex/cairngorm/feed" rel="self" type="application/rss+xml" />
	<link>http://www.curiousfind.com/blog</link>
	<description>Web development by Jamie McDaniel</description>
	<lastBuildDate>Tue, 13 Dec 2011 05:20:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Notes on learning Cairngorm</title>
		<link>http://www.curiousfind.com/blog/14</link>
		<comments>http://www.curiousfind.com/blog/14#comments</comments>
		<pubDate>Fri, 12 Sep 2008 18:23:14 +0000</pubDate>
		<dc:creator>Jamie McDaniel</dc:creator>
				<category><![CDATA[Cairngorm]]></category>

		<guid isPermaLink="false">http://www.curiousfind.com/blog/?p=14</guid>
		<description><![CDATA[Here is how I added Cairngorm to my skill-set (after first gaining enough Flex experience to understand why you would use an architectural framework). David Tucker&#8217;s 5-Part Series David&#8217;s excellent articles and accompanying videos are what I would highly recommend starting with. Getting Started with Cairngorm &#8211; Part 1 Getting Started with Cairngorm &#8211; Part [...]]]></description>
			<content:encoded><![CDATA[<p>Here is how I added Cairngorm to my skill-set (after first gaining enough Flex experience to understand why you would use an architectural framework).</p>
<h3>David Tucker&#8217;s 5-Part Series</h3>
<p>David&#8217;s excellent articles and accompanying videos are what I would highly recommend starting with.</p>
<ul>
<li> <a href="http://www.davidtucker.net/2007/10/07/getting-started-with-cairngorm-%E2%80%93-part-1/">Getting Started with Cairngorm &#8211; Part 1</a></li>
<li><a href="http://www.davidtucker.net/2007/10/18/cairngorm-part-2/">Getting Started with Cairngorm &#8211; Part 2</a></li>
<li><a href="http://www.davidtucker.net/2007/10/29/cairngorm-part-3/">Getting Started with Cairngorm &#8211; Part 3</a></li>
<li><a href="http://www.davidtucker.net/2007/11/07/cairngorm-part-4/">Getting Started with Cairngorm &#8211; Part 4</a></li>
<li><a href="http://www.davidtucker.net/2007/11/30/getting-started-with-cairngorm-%E2%80%93-part-5/">Getting Started with Cairngorm &#8211; Part 5</a></li>
</ul>
<h3>CairngormStore Example</h3>
<p>Or rather <a href="http://www.brightworks.com/flex_ability/?p=61">Douglas McCarroll&#8217;s update</a> of Chen Bekor&#8217;s ModifiedCairngormStore.  Douglas updated it for Cairngorm 2.2.1 and Flex 3.</p>
<h3>10 Tips for Working with Cairngorm</h3>
<p>Jesse Warden&#8217;s <a href="http://jessewarden.com/2007/08/10-tips-for-working-with-cairngorm.html">10 Tips for Working with Cairngorm</a>.  Tip #10 about not having nested views dispatch CairngormEvents (but rather dispatch regular events &#8212; or your own custom events that extend the event class &#8212; to the main view which would then dispatch a CairngormEvent) is a best practice to keep in mind when studying the CairngormStore example.</p>
<h3>Adobe Consulting&#8217;s 6-Part Article</h3>
<p>Steven Webster and Leon Tanner of Adobe Consulting wrote <a href="http://www.adobe.com/devnet/flex/articles/cairngorm_pt1.html">Developing Flex RIAs with Cairngorm microarchitecture</a>. The article has a lot of really good information in it and uses the CairngormStore as an example (although you will want to get the updated CairngormStore from the link above).</p>
<p>Here are some nuggets I gleaned from the articles:</p>
<p><strong>Nugget #1</strong></p>
<blockquote><p>&#8230;resist the opportunity to scatter state all over your application as strings, numbers, Booleans, and all manner of other primitive objects. &#8230;we strongly advocate that the client hold the data &#8212; as state, model, or whatever you want to call it &#8212; as objects that have semantic meaning.</p></blockquote>
<p style="padding-left: 30px;">Source: <a href="http://www.adobe.com/devnet/flex/articles/cairngorm_pt2_04.html">part 2, page 4</a></p>
<p>The use of value objects (or data transfer objects) was brought up in other places and is not specific to Cairngorm.  Still, it is good stuff that bears repeating.</p>
<p><strong>Nugget #2</strong></p>
<blockquote><p>When you create components that rely upon client-side data, it is all too easy to create a direct reference to a Singleton model, such as <code>ShopModelLocator</code>. Indeed this is true throughout the application. We discourage this approach. Instead, consider passing the model and/or its properties down through a hierarchy of your view components, for a cleaner and more thoughtful solution.</p></blockquote>
<p style="padding-left: 30px;">Source: <a href="http://www.adobe.com/devnet/flex/articles/cairngorm_pt2_07.html">part 2, page 7</a></p>
<p>The goal is to make components more reusable. If you have components importing the modelLocator, using the <code>getInstance</code> method, and then binding directly to data in the Cairngorm modelLocator instance, then those components are coupled to your project and/or the Cairngorm framework.</p>
<p>The argument behind not using CairngormEvents other than in your main view (Jesse Warden&#8217;s tip #10 from above) is the same reasoning here &#8212; reusablity and loosely coupled components.  Ideally your components could be used outside of the Cairngorm framework.</p>
<p>The CairngormStore example follows this in some places, but not in others. In <code>Main.mxml</code>, for instance, a ProductVO is &#8220;injected&#8221; into the <code>selectedItem</code> attribute of the <code>&lt;details:ProductDetails&gt;</code> component. However other components, such as <code>ProductsAndCheckoutViewStack.mxml</code>, import the ModelLocator and use <code>ShopModelLocator.getInstance()</code>.</p>
<p>Regarding the CairngormStore and best practices, Alistair McLeod states in a <a href="http://weblogs.macromedia.com/amcleod/archives/2008/08/cairngorm_moved.html#c76304">comment on his blog</a> that &#8220;&#8230;you make a good point with CairngormStore &#8211; looking at the application now, it definitely does not advertise our best practices of building applications with Cairngorm, and that&#8217;s something else we want to rectify&#8230;&#8221;</p>
<p>I am still trying to fully understand best practices regarding reusability. There is a critique of Cairngorm (or rather a certain use of the Model Locator pattern) <a href="http://blog.iconara.net/2008/04/13/architectural-atrocities-part-x-cairngorms-model-locator-pattern/">here</a> where the author mentions some of this. Another blog post on Cairgorm with some discussion about the Model Locator and coupling components to it is <a href="http://www.jeffryhouser.com/index.cfm/2008/3/27/Learning-Cairngorm-Part-6-Dealing-with-the-Singleton">here</a>.</p>
<p>(And just when I thought I was beginning to understand reusability, I saw this <a href="http://www.onflex.org/ted/2008/08/creating-reusable-components-by-ben.php">session from 360Flex</a> about there being two &#8220;levels&#8221; of reusability &#8212; loosely-coupled components and polished, fit for cataloging/distribution components. The gist being that a truly reusable component takes a lot more time to do and involves such things as allowing css styling and programming default behaviors.)</p>
<p><strong>Nugget #3</strong></p>
<blockquote><p>Developers should always seek to extract these classes from the Cairngorm architecture. Pulling business logic out of  commands and encapsulating into classes is a classic implementation of <em>Extract  class</em> refactoring.</p></blockquote>
<p style="padding-left: 30px;">Source: <a href="http://www.adobe.com/devnet/flex/articles/cairngorm_pt4_05.html">part 4, page 5</a></p>
<p>This is in reference to the <code>AddProductToShoppingCartCommand</code> in CairngormStore. The execute function of this command class just calls a function on shoppingCart stored in the model locator.</p>
<div class="actionscript geshi no actionscript" style="font-family:monospace;">
<ol>
<li class="li1">
<div class="de1">ShopModelLocator.<span class="me1">getInstance</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">shoppingCart</span>.<span class="me1">addElement</span><span class="br0">&#40;</span>shoppingEvent.<span class="me1">product</span>, shoppingEvent.<span class="me1">quantity</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>Rather than have a lot of complex business logic associated with shopping cart behavior in the <code>AddProductToShoppingCartCommand</code> class, such business logic is encapsulated in a ShoppingCart class (which, in the CairngormStore example, was stored in the model folder.)</p>
<p><strong>Nugget #4</strong></p>
<blockquote><p>&#8230;you and your team will approach the addition of each and             every feature to a Cairngorm application in the same way. In short, you will             add an event to the controller, register it with a Command class, and implement             the Command class to do all the work. With this approach you can drive the             development of your application with feature after feature, in a consistent,             predictable manner that scales well.</p></blockquote>
<p style="padding-left: 30px;">Source: <a href="http://www.adobe.com/devnet/flex/articles/cairngorm_pt4_06.html">part 4, page 6</a></p>
<p>This is a good review of the flow in Cairngorm and the benefits of using an architectural framework.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.curiousfind.com/blog/14/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

