<?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>Flash Moments &#187; Strategy Pattern</title>
	<atom:link href="http://flashmoments.novelastudios.com/tag/strategy-pattern/feed/" rel="self" type="application/rss+xml" />
	<link>http://flashmoments.novelastudios.com</link>
	<description>ActionScript, Flash, and Flex</description>
	<lastBuildDate>Wed, 01 Dec 2010 02:59:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Tween Library Preferences and Strategy Patterns</title>
		<link>http://flashmoments.novelastudios.com/actionscript/tween-library-preferences-strategy-patterns/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://flashmoments.novelastudios.com/actionscript/tween-library-preferences-strategy-patterns/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 03:48:52 +0000</pubDate>
		<dc:creator>johntimothybailey</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Programming Architecture]]></category>
		<category><![CDATA[Programming Practice]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[Strategy Pattern]]></category>

		<guid isPermaLink="false">http://flashmoments.novelastudios.com/?p=60</guid>
		<description><![CDATA[Problem: When it comes to Tween libraries, it&#8217;s either a project&#8217;s requirements and/or developer personal preferences that can conflict in selecting a library. Honestly, the library shouldn&#8217;t matter. The importance is that the objects are tweened. This is especially important when it comes to open-source projects, as the issue only compounds where it&#8217;s much more [...]]]></description>
			<content:encoded><![CDATA[<div style="float:left;margin:0px 0px 0px 0px;"></div><p><strong>Problem</strong>:<br />
When it comes to Tween libraries, it&#8217;s either a project&#8217;s requirements and/or developer personal preferences that can conflict in selecting a library. Honestly, <span style="text-decoration: underline;">the library shouldn&#8217;t matter</span>. <span style="text-decoration: underline;">The importance is that the objects are tweened</span>. This is especially important when it comes to open-source projects, as the issue only compounds where it&#8217;s much more likely that both personal preferences and project requirements will both be the issue with the open-source project.</p>
<p><strong>Solution:</strong> Use the Strategy Pattern</p>
<p><strong>Example</strong><em> (real-life example)</em>: <a title="Duncan Reid's Blog" href="http://blog.hy-brid.com/" target="_blank">Duncan Reid</a> created a <a title="Duncan Reid's ToolTip Class" href="http://blog.hy-brid.com/flash/25/simple-as3-tooltip/" target="_blank">ToolTip UI class</a> for ActionScript3. The problem I ran into was that fl.transitions.Tween was being used and I was working on an AS3 application that is using the now <a href="http://blog.greensock.com/tweenlite/" target="_blank">Greensock&#8217;s TweenLite</a>. The solution that Duncan and I discussed was to use a Strategy Pattern to decouple the Tween library from the ToolTip class itself and offload the reference onto implementation. In other words, by utilizing the Strategy Pattern, it allows the developer to decide which tweening library he/she would prefer to use. For Duncan Reid&#8217;s ToolTip UI I did the following:</p>
<ul>
<li>Added New Files:
<ul>
<li><em>com.hybrid.ui.strategies.IToolTipTweenStrategy</em></li>
<li><em>com.hybrid.ui.strategies.ToolTipTweenStrategy</em> &#8211; The only place where <em>fl.transitions.Tween</em> is being used/referenced</li>
</ul>
</li>
<li>ToolTip now has a required constructor parameter tweenStrategy which will accept anything implementing the IToolTipTweenStrategy</li>
</ul>
<p>This now means that the ToolTip UI class depends on one thing &#8211; the Tween Strategy. In fact, the strategy could be set to null (not given to the ToolTip), then no tweening would take place. Instead, the tooltip would just display or hide immediately. As such, the required construction param could be made optional (ie default set to null).</p>
<p>In action this simply looks like</p>
<pre lang="Actionscript">  new ToolTip(new com.hybrid.ui.strategies.ToolTipTweenStrategy)
  //OR
  new ToolTip(new com.novelastudios.ui.strategies.ToolTipTweenStrategy)</pre>
<p><strong>Source Files / Source Examples</strong> <em>(using Duncan Reid&#8217;s ToolTip UI)</em></p>
<ul>
<li>Example of dynamic strategy changing ( <a title="ToolTip Tween Strategy Visual Demo" href="http://sources.novelastudios.com/flash/tooltip/ToolTipExample.html" target="_blank">visual demo</a> / <a href="http://sources.novelastudios.com/flash/tooltip/srcview/index.html" target="_blank">source</a> )
<ul>
<li>Click the Radio Buttons at the top of the visual demo to switch between the different strategies.</li>
</ul>
</li>
<li>Implementing it into Duncan&#8217;s original example
<ul>
<li>Using fl.transitions.Tween ( <a href="http://sources.novelastudios.com/flash/tooltip/ToolTip_Fl_Tween.html" target="_blank">visual demo</a> / source <a href="http://sources.novelastudios.com/flash/tooltip/srcview/source/ToolTip_Fl_Tween.fla" target="_blank">.fla</a> | <a href="http://sources.novelastudios.com/flash/tooltip/srcview/source/ToolTip_Fl_Tween.as" target="_blank">.as</a> )</li>
<li>Using com.greensocks.TweenLite ( <a href="http://sources.novelastudios.com/flash/tooltip/ToolTip_Greensock_Tween.html" target="_blank">visual demo </a>/ source <a href="http://sources.novelastudios.com/flash/tooltip/srcview/source/ToolTip_Greensock_Tween.fla" target="_blank">.fla</a> | <a href="http://sources.novelastudios.com/flash/tooltip/srcview/source/ToolTip_Greensock_Tween.as" target="_blank">.as</a> )</li>
</ul>
</li>
</ul>
<p><strong>Note</strong><br />
The above source is not officially supported / maintained by Duncan Reid and as such I recommend that this simply be used as an example and refer you to his site and source code for production use.</p>
<p><strong>Additional Information</strong><br />
For more information on the Strategy Pattern with ActionScript3 checkout the following:</p>
<ul>
<li><a title="Simple Explanation" href="http://ntt.cc/2008/10/07/gang-of-four-gof-design-patterns-in-actionscript-strategy.html" target="_blank">Brief Explanation</a></li>
<li><a title="Bill Sanders' Explanation of the Strategy Pattern" href="http://www.as3dp.com/2008/11/09/actionscript-30-strategy-design-pattern-under-no-conditionals/" target="_blank">Bill Sanders&#8217; Explanation</a></li>
<li><a title="Sean Moore's Explanation" href="http://www.insideria.com/2008/11/exploring-the-strategy-design.html" target="_blank">Sean Moore&#8217;s Explanation</a></li>
</ul>
<img src="http://flashmoments.novelastudios.com/?ak_action=api_record_view&id=60&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://flashmoments.novelastudios.com/actionscript/tween-library-preferences-strategy-patterns/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

