<?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>Tweenpix &#187; tutorial</title>
	<atom:link href="http://blog.tweenpix.net/tag/tutorial/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.tweenpix.net</link>
	<description>Behind the mask</description>
	<lastBuildDate>Wed, 02 Mar 2011 22:54:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>IPhone SDK &#8211; tutoriaux par Keith Peters</title>
		<link>http://blog.tweenpix.net/2008/12/31/iphone-sdk-tutoriaux-par-keith-peters/</link>
		<comments>http://blog.tweenpix.net/2008/12/31/iphone-sdk-tutoriaux-par-keith-peters/#comments</comments>
		<pubDate>Wed, 31 Dec 2008 12:35:53 +0000</pubDate>
		<dc:creator>Francis Bourre</dc:creator>
				<category><![CDATA[news]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[keith peters]]></category>
		<category><![CDATA[objective c]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://blog.tweenpix.net/?p=761</guid>
		<description><![CDATA[En attendant la sortie du player Flash sur IPhone, voici une série de tutoriaux pour bien démarrer avec l&#8217;IPhone SDK et L&#8217;Objective C. Keith Peters vous propose dans cette série de créer une balle animée avec gravité et rebond, draggable au toucher et sensible à l&#8217;accéléromètre. Le SDK et la syntaxe sont tellement déroutants pour [...]]]></description>
			<content:encoded><![CDATA[<p>En attendant la sortie du player Flash sur IPhone, voici une série de tutoriaux pour bien démarrer avec l&#8217;<a href="http://developer.apple.com/iphone/">IPhone SDK</a> et L&#8217;<a href="http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Introduction/chapter_1_section_1.html">Objective C</a>.<br />
Keith Peters vous propose dans cette série de créer une balle animée avec gravité et rebond, draggable au toucher et sensible à l&#8217;accéléromètre.<br />
Le SDK et la syntaxe sont tellement déroutants pour un développeur Flash, qu&#8217;il est toujours intéressant de bénéficier de l&#8217;approche de ses congénères.</p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/6wPaBeqyWYA&#038;color1=0xb1b1b1&#038;color2=0xcfcfcf&#038;hl=en&#038;feature=player_embedded&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/6wPaBeqyWYA&#038;color1=0xb1b1b1&#038;color2=0xcfcfcf&#038;hl=en&#038;feature=player_embedded&#038;fs=1" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="344"></embed></object></p>
<p>Voici la liste complète des tutoriaux:<br />
<a href="http://www.bit-101.com/blog/?p=1784">- Part 1</a><br />
<a href="http://www.bit-101.com/blog/?p=1793">- Part 2</a><br />
<a href="http://www.bit-101.com/blog/?p=1798">- Part 3</a><br />
<a href="http://www.bit-101.com/blog/?p=1812">- Part 4</a><br />
<a href="http://www.bit-101.com/blog/?p=1824">- Part 5</a></p>
<p>Pour finir, voici 2 autres liens intéressants sur l&#8217;Objective C et L&#8217;IPhone SDK appréhendés encore par des développeurs Flash, avec une mention particulière pour le premier:<br />
<a href="http://andyj.be/blog/?cat=20">Andy Jacobs &#8211; from actionscript to cocoa touch</a><br />
<a href="http://labs.bigspaceship.com/2008/12/04/actionscript-to-iphone-its-magic/">Big Spaceships Labs &#8211; Porting actionscript to iPhone, not magic!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tweenpix.net/2008/12/31/iphone-sdk-tutoriaux-par-keith-peters/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>hello world with LowRA</title>
		<link>http://blog.tweenpix.net/2008/01/28/hello-world-with-lowra/</link>
		<comments>http://blog.tweenpix.net/2008/01/28/hello-world-with-lowra/#comments</comments>
		<pubDate>Mon, 28 Jan 2008 13:11:51 +0000</pubDate>
		<dc:creator>Francis Bourre</dc:creator>
				<category><![CDATA[tutorial]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[lowra]]></category>

		<guid isPermaLink="false">http://blog.tweenpix.net/?p=738</guid>
		<description><![CDATA[That&#8217;s a quick example of a basic applicationContext.xml working with LowRA rev410. To read and parse this file, you need to make an instance of ApplicationLoader in your application, and call its execute method. &#60;beans&#62; &#160; &#160; &#160; &#160; &#60;root&#62; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#60;txt id=&#34;txt&#34; type=&#34;flash.text.TextField&#34;&#62; &#160; &#160; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>That&#8217;s a quick example of a basic applicationContext.xml working with <a href="http://code.google.com/p/lowra">LowRA</a> rev410.</p>
<div class="captionfull"><img src="http://blog.tweenpix.net/wp-content/gallery/general/lowra.jpg" alt="But who’s LowRA ?" />
</p>
</div>
<p>To read and parse this file, you need to make an instance of <a href="http://lowra.googlecode.com/svn/trunk/src/com/bourre/ioc/load/ApplicationLoader.as">ApplicationLoader</a> in your application, and call its execute method.</p>
<p><code class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;beans<span style="font-weight: bold; color: black;">&gt;</span></span></span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;root<span style="font-weight: bold; color: black;">&gt;</span></span></span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;txt</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;txt&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;flash.text.TextField&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Hello world!&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;autoSize&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;left&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;method-call</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;setTextFormat&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;argument</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;tf&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/method-call<span style="font-weight: bold; color: black;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/txt<span style="font-weight: bold; color: black;">&gt;</span></span></span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/root<span style="font-weight: bold; color: black;">&gt;</span></span></span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;tf</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;tf&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;flash.text.TextFormat&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;argument</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Arial&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;argument</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;Number&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;30&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;argument</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;Number&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;0xFF0000&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/tf<span style="font-weight: bold; color: black;">&gt;</span></span></span></p>
<p><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/beans<span style="font-weight: bold; color: black;">&gt;</span></span></span></code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tweenpix.net/2008/01/28/hello-world-with-lowra/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>hello world en amfphp avec flex 2.0</title>
		<link>http://blog.tweenpix.net/2006/01/03/hello-world-en-amfphp-avec-flex-20/</link>
		<comments>http://blog.tweenpix.net/2006/01/03/hello-world-en-amfphp-avec-flex-20/#comments</comments>
		<pubDate>Tue, 03 Jan 2006 09:53:12 +0000</pubDate>
		<dc:creator>Francis Bourre</dc:creator>
				<category><![CDATA[tech]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[amfphp]]></category>
		<category><![CDATA[flex]]></category>

		<guid isPermaLink="false">http://blog.tweenpix.net/?p=235</guid>
		<description><![CDATA[En complément du billet de Jesse Warden, voici un exemple synthétique de connexion AMFPHP en AS3. Un billet qui me permet d’inaugurer la sortie officielle d’AMFPHP 1.0 et saluer Patrick Mineault pour son dévouement. Pour ceux que ça intéresse, pixlib proposera en révision 23 un puissant configurateur d’application + une suppression totale des dépendances avec [...]]]></description>
			<content:encoded><![CDATA[<p>En complément du <a hreflang="fr" href="http://www.jessewarden.com/archives/2005/12/amfphp_10_works.html">billet</a> de Jesse Warden, voici un exemple synthétique de connexion AMFPHP en AS3.</p>
<p>Un billet qui me permet d’inaugurer la sortie officielle d’<a hreflang="fr" href="http://www.amfphp.org/">AMFPHP 1.0</a> et saluer <a hreflang="fr" href="http://www.5etdemi.com/blog/">Patrick Mineault</a> pour son dévouement.</p>
<p>Pour ceux que ça intéresse, pixlib proposera en révision 23 un puissant configurateur d’application + une suppression totale des dépendances avec le package <a hreflang="fr" href="http://www.luminicbox.com/blog/?page=post&amp;id=2">Luminic</a> et dans une prochaine révision, un package remoting autonome, c’est à dire sans aucune dépendance avec le package mx d’Adobe.</p>
<p>Je vous souhaite une bonne année à tous!</p>
<pre>package
<span style="color: #000000;">{</span>
	<span style="color: #0000cc;">import</span> flash.<span style="color: #0000cc;">net</span>.<span style="color: #0000cc;">NetConnection</span>;
	<span style="color: #0000cc;">import</span> flash.<span style="color: #0000cc;">net</span>.<span style="color: #0000cc;">ObjectEncoding</span>;

	<span style="color: #0000cc;">public</span> <span style="font-weight: bold; color: #0000cc;">class</span> RemotingConnection <span style="color: #0000cc;">extends</span> <span style="color: #0000cc;">NetConnection</span>
	<span style="color: #000000;">{</span>
		<span style="color: #0000cc;">public</span> <span style="font-weight: bold; color: #0000cc;">function</span> RemotingConnection<span style="color: #000000;">(</span> sURL:<span style="color: #0000cc;">String</span> <span style="color: #000000;">)</span>
		<span style="color: #000000;">{</span>
			objectEncoding = ObjectEncoding.<span style="color: #0000cc;">AMF0</span>;
			<span style="color: #0000cc;">if</span> <span style="color: #000000;">(</span>sURL<span style="color: #000000;">)</span> <span style="color: #0000cc;">connect</span><span style="color: #000000;">(</span> sURL <span style="color: #000000;">)</span>;
		<span style="color: #000000;">}</span>

		<span style="color: #0000cc;">public</span> <span style="font-weight: bold; color: #0000cc;">function</span> AppendToGatewayUrl<span style="color: #000000;">(</span> s : <span style="color: #0000cc;">String</span> <span style="color: #000000;">)</span> : <span style="color: #0000cc;">Void</span>
		<span style="color: #000000;">{</span>
			<span style="font-style: italic; color: #990000;">//</span>
		<span style="color: #000000;">}</span>
	<span style="color: #000000;">}</span>
<span style="color: #000000;">}</span></pre>
<pre>&lt;?<span style="color: #0000cc;">xml</span> <span style="color: #0000cc;">version</span>=<span style="color: #006600;">"1.0"</span> encoding=<span style="color: #006600;">"utf-8"</span>?&gt;

	&lt;mx:Application xmlns:mx=<span style="color: #006600;">"http://www.macromedia.com/2005/mxml"</span>
					xmlns=<span style="color: #006600;">"*"</span>
					creationComplete=<span style="color: #006600;">"initApplication()"</span>&gt;

	&lt;mx:Canvas <span style="color: #0000cc;">width</span>=<span style="color: #006600;">"100%"</span> <span style="color: #0000cc;">height</span>=<span style="color: #006600;">"100%"</span>&gt;
		&lt;mx:TextArea <span style="color: #0000cc;">width</span>=<span style="color: #006600;">"100%"</span> <span style="color: #0000cc;">height</span>=<span style="color: #006600;">"100%"</span> id=<span style="color: #006600;">"output"</span>/&gt;
	&lt;/mx:Canvas&gt;

	&lt;mx:Script&gt;
		&lt;!<span style="color: #000000;">[</span>CDATA<span style="color: #000000;">[</span>
			<span style="color: #0000cc;">import</span> flash.<span style="color: #0000cc;">net</span>.<span style="color: #0000cc;">Responder</span>;

			<span style="color: #0000cc;">public</span> <span style="font-weight: bold; color: #0000cc;">var</span> gateway : RemotingConnection;

			<span style="color: #0000cc;">public</span> <span style="font-weight: bold; color: #0000cc;">function</span> initApplication<span style="color: #000000;">(</span><span style="color: #000000;">)</span>
			<span style="color: #000000;">{</span>
				gateway = <span style="font-weight: bold; color: #0000cc;">new</span> RemotingConnection<span style="color: #000000;">(</span> <span style="color: #006600;">"http://localhost/flashservices/gateway.php"</span> <span style="color: #000000;">)</span>;
				gateway.<span style="color: #0000cc;">call</span><span style="color: #000000;">(</span> <span style="color: #006600;">"HelloWorld.say"</span>, <span style="font-weight: bold; color: #0000cc;">new</span> Responder<span style="color: #000000;">(</span>onResult, onFault<span style="color: #000000;">)</span>, <span style="color: #006600;">"hello world"</span><span style="color: #000000;">)</span>;
			<span style="color: #000000;">}</span>

			<span style="color: #0000cc;">public</span> <span style="font-weight: bold; color: #0000cc;">function</span> onResult<span style="color: #000000;">(</span> result : <span style="color: #0000cc;">Object</span> <span style="color: #000000;">)</span> : <span style="color: #0000cc;">Void</span>
			<span style="color: #000000;">{</span>
				output.<span style="color: #0000cc;">text</span> = result;
			<span style="color: #000000;">}</span>

			<span style="color: #0000cc;">public</span> <span style="font-weight: bold; color: #0000cc;">function</span> onFault<span style="color: #000000;">(</span> fault : <span style="color: #0000cc;">Object</span> <span style="color: #000000;">)</span> : <span style="color: #0000cc;">Void</span>
			<span style="color: #000000;">{</span>
				output.<span style="color: #0000cc;">text</span> = fault;
			<span style="color: #000000;">}</span>
		<span style="color: #000000;">]</span><span style="color: #000000;">]</span>&gt;
	&lt;/mx:Script&gt;

&lt;/mx:Application&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.tweenpix.net/2006/01/03/hello-world-en-amfphp-avec-flex-20/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ColorMatrixFilter</title>
		<link>http://blog.tweenpix.net/2005/09/21/colormatrixfilter/</link>
		<comments>http://blog.tweenpix.net/2005/09/21/colormatrixfilter/#comments</comments>
		<pubDate>Wed, 21 Sep 2005 18:02:58 +0000</pubDate>
		<dc:creator>Francis Bourre</dc:creator>
				<category><![CDATA[tutorial]]></category>
		<category><![CDATA[colormatrixfilter]]></category>

		<guid isPermaLink="false">http://blog.tweenpix.net/?p=227</guid>
		<description><![CDATA[Flash8 est sorti, et c&#8217;est l&#8217;occasion de voir ce qu&#8217;il a de nouveau sous le capot. Commençons donc par la classe ColorMatrixFilter. Unique prérequis, qui facilitera la compréhension des exemples AS 2.0: Vous vous êtes déjà familiarisés quelque peu avec l&#8217;utilisation du package flash.filters. ColorMatrixFilter, de quoi s&#8217;agit-il ? Ce filtre applique une matrice de transformation [...]]]></description>
			<content:encoded><![CDATA[<p>Flash8 est sorti, et c&#8217;est l&#8217;occasion de voir ce qu&#8217;il a de nouveau sous le capot.</p>
<p>Commençons donc par la classe ColorMatrixFilter.</p>
<p>Unique prérequis, qui facilitera la compréhension des exemples AS 2.0: Vous vous êtes déjà familiarisés quelque peu avec l&#8217;utilisation du package <strong>flash.filters</strong>.</p>
<ul>
<li><strong>ColorMatrixFilter</strong>, de quoi s&#8217;agit-il ?</li>
</ul>
<p>Ce filtre applique une matrice de transformation sur les valeurs de couleur et alpha RGBA de chaque pixel d&#8217;une image en entrée pour produire une image résultat avec un nouveau jeu de valeurs.</p>
<ul>
<li>Mais qu&#8217;est ce qu&#8217;une <strong>matrice</strong> pour commencer ?</li>
</ul>
<p>Une matrice, c&#8217;est un tableau bi-dimensionnel de réels constitué de lignes et colonnes.<br />
Une matrice 4&#215;5 est donc ni plus ni moins un tableau contenant 4 lignes et 5 colonnes.</p>
<pre><span style="color: #000000;">[</span>	<span style="color: #000000;">0</span>,	<span style="color: #000000;">1</span>,	<span style="color: #000000;">2</span>,	<span style="color: #000000;">3</span>,	<span style="color: #000000;">4</span>,
	<span style="color: #000000;">5</span>, 	<span style="color: #000000;">6</span>, 	<span style="color: #000000;">7</span>, 	<span style="color: #000000;">8</span>, 	<span style="color: #000000;">9</span>,
	<span style="color: #000000;">10</span>,	<span style="color: #000000;">11</span>,	<span style="color: #000000;">12</span>,	<span style="color: #000000;">13</span>,	<span style="color: #000000;">14</span>,
	<span style="color: #000000;">15</span>,	<span style="color: #000000;">16</span>,	<span style="color: #000000;">17</span>,	<span style="color: #000000;">18</span>,	<span style="color: #000000;">19</span>	<span style="color: #000000;">]</span></pre>
<ul>
<li>Voici maintenant la formule de base qui permet de recalculer le RGBA d&#8217;une image à partir d&#8217;une matrice 4&#215;5 de valeurs, c&#8217;est à dire en pratique, à partir d&#8217;un Array composé de 20 réels indexés de 0 à 19 (comme ci-dessus).</li>
</ul>
<pre>Red = 	(a[0]*Red)  + (a[1]*Green)  + (a[2]*Blue)  + (a[3]*Alpha)  + a[4]
Green = (a[5]*Red)  + (a[6]*Green)  + (a[7]*Blue)  + (a[8]*Alpha)  + a[9]
Blue = 	(a[10]*Red) + (a[11]*Green) + (a[12]*Blue) + (a[13]*Alpha) + a[14]
Alpha = (a[15]*Red) + (a[16]*Green) + (a[17]*Blue) + (a[18]*Alpha) + a[19]</pre>
<p>Comme vous pouvez le remarquer, pour calculer la valeur finale de chacun des 4 canaux, on multiplie la valeur d&#8217;origine de chaque pixel de l&#8217;image par la valeur correspondante de la matrice de transformation et on ajoute au total (si stipulée, c&#8217;est à dire non nulle) une valeur offset (située entre -255 et 255), respectivement les valeurs indexées 4, 9, 14 et 19.</p>
<ul>
<li>Voici maintenant une matrice d&#8217;identité, c&#8217;est à dire une matrice carrée, dont tous les composants sont nuls sauf les éléments de la première diagonale qui valent un (on fait ici abstraction de la 5ème colonne, les valeurs offsets).</li>
</ul>
<p>[1,0,0,0,0,<br />
0,1,0,0,0,<br />
0,0,1,0,0,<br />
0,0,0,1,0];</p>
<p>Faisons le calcul du résultat :</p>
<pre>Red = 	(1*Red) + (0*Green) + (0*Blue) + (0*Alpha) + 0
Green = (0*Red) + (1*Green) + (0*Blue) + (0*Alpha) + 0
Blue = 	(0*Red) + (0*Green) + (1*Blue) + (0*Alpha) + 0
Alpha = (0*Red) + (0*Green) + (0*Blue) + (1*Alpha) + 0</pre>
<p><ins>On obtient au final:</ins> Red = 	(1*Red)<br />
Green = (1*Green)<br />
Blue = 	(1*Blue)<br />
Alpha = (1*Alpha)</p>
<p><ins>Autrement dit:</ins><br />
Red = 	Red<br />
Green = Green<br />
Blue = 	Blue<br />
Alpha = Alpha</p>
<p>Cette matrice a donc pour particularité d&#8217;appliquer aucune transformation sur les valeurs RGBA d&#8217;une image. Elle map chacun des composants à sa valeur initiale.<br />
Elle constitue donc en définitive un bon point de départ pour toutes vos expérimentations.</p>
<ul>
<li>Nous allons maintenant créer le négatif d&#8217;une image. On affecte à chacun des canaux (RGB) sa valeur maximale à laquelle on retranche la valeur initiale de l&#8217;image.</li>
</ul>
<pre><span style="color: #000000;">[</span>	-<span style="color: #000000;">1</span>,	<span style="color: #000000;">0</span>,	<span style="color: #000000;">0</span>,	<span style="color: #000000;">0</span>,	<span style="color: #000000;">255</span>,
	<span style="color: #000000;">0</span>,	-<span style="color: #000000;">1</span>,	<span style="color: #000000;">0</span>,	<span style="color: #000000;">0</span>,	<span style="color: #000000;">255</span>,
	<span style="color: #000000;">0</span>,	<span style="color: #000000;">0</span>,	-<span style="color: #000000;">1</span>,	<span style="color: #000000;">0</span>,	<span style="color: #000000;">255</span>,
	<span style="color: #000000;">0</span>,	<span style="color: #000000;">0</span>,	<span style="color: #000000;">0</span>,	<span style="color: #000000;">1</span>,	<span style="color: #000000;">0</span><span style="color: #000000;">]</span></pre>
<p><ins>C&#8217;est à dire</ins>:<br />
Red = 255 &#8211; Red<br />
Green = 255 &#8211; Green<br />
Blue = 255 &#8211; Blue<br />
Alpha = Alpha</p>
<pre><span style="color: #0000cc;">import</span> flash.<span style="color: #0000cc;">filters</span>.*;

<span style="color: #0000cc; font-weight: bold;">var</span> negativeTransform:ColorMatrixFilter = <span style="color: #0000cc; font-weight: bold;">new</span> ColorMatrixFilter<span style="color: #000000;">(</span>
	<span style="color: #0000cc; font-weight: bold;">new</span> <span style="color: #0000cc;">Array</span> <span style="color: #000000;">(</span>
	-<span style="color: #000000;">1</span>,	<span style="color: #000000;">0</span>,	<span style="color: #000000;">0</span>,	<span style="color: #000000;">0</span>,	<span style="color: #000000;">255</span>,
        <span style="color: #000000;">0</span>,	-<span style="color: #000000;">1</span>,	<span style="color: #000000;">0</span>,	<span style="color: #000000;">0</span>,	<span style="color: #000000;">255</span>,
        <span style="color: #000000;">0</span>,	<span style="color: #000000;">0</span>,	-<span style="color: #000000;">1</span>,	<span style="color: #000000;">0</span>,	<span style="color: #000000;">255</span>,
        <span style="color: #000000;">0</span>,	<span style="color: #000000;">0</span>,	<span style="color: #000000;">0</span>,	<span style="color: #000000;">1</span>,	<span style="color: #000000;">0</span>
		<span style="color: #000000;">)</span><span style="color: #000000;">)</span>;

<span style="color: #990000; font-style: italic;">// On applique le filtre à une occurrence en le passant en argument </span>
<span style="color: #990000; font-style: italic;">// à l'intérieur d'un tableau. </span>
<span style="color: #990000; font-style: italic;">// Ce tableau représente la liste des filtres à appliquer.</span>

<span style="color: #990000; font-style: italic;">// Le MovieClip sera mis automatiquement en cache bitmap </span>
<span style="color: #990000; font-style: italic;">// (cacheAsBitmap == true) afin d'être traité comme une image.</span>

mc.<span style="color: #0000cc;">filters</span> = <span style="color: #000000;">[</span> negativeTransform <span style="color: #000000;">]</span>;</pre>
<p>NB: Si l&#8217;array contient plusieurs filtres, l&#8217;indexage de ceux-ci n&#8217;est pas anecdotique. Il s&#8217;agit de l&#8217;ordre dans lequel vont être appliqués les différents traitements sur le clip cible.</p>
<p><strong>Après cette entrée en matière, vous disposez maintenant des outils nécessaires pour aborder les différents algorithmes disponibles sur le sujet.</strong></p>
<p>Pour constituer des exemples pratiques en AS 2.0, nous allons partir d&#8217;un article qui fait référence dans le domaine:<br />
<a hreflang="fr" href="http://www.sgi.com/misc/grafica/matrix/">Matrix Operations for Image Processing</a> par Paul Haeberli.</p>
<p><ins><strong>-Premier exemple:</strong></ins></p>
<p><ins><em>Converting to Luminance</em></ins><br />
<em>Pour convertir une image en noir et blanc, on utilise cette matrice:</em></p>
<pre>    float mat<span style="color: #000000;">[</span><span style="color: #000000;">4</span><span style="color: #000000;">]</span><span style="color: #000000;">[</span><span style="color: #000000;">4</span><span style="color: #000000;">]</span> = <span style="color: #000000;">{</span>
        rwgt,   rwgt,   rwgt,   <span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,
        gwgt,   gwgt,   gwgt,   <span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,
        bwgt,   bwgt,   bwgt,   <span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,
        <span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,    <span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,    <span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,    <span style="color: #000000;">1</span>.<span style="color: #000000;">0</span>,
    <span style="color: #000000;">}</span>;</pre>
<p><em>Où rwgt vaut 0.3086, gwgt 0.6094, et bwgt is 0.0820. This is the luminance vector.</em></p>
<p><ins>Ce qui nous donne en ActionScript:</ins></p>
<pre><span style="color: #0000cc;">import</span> flash.<span style="color: #0000cc;">filters</span>.*;

<span style="color: #990000; font-style: italic;">// La luminance, c'est la partie du signal vidéo qui contient les informations </span>
<span style="color: #990000; font-style: italic;">// concernant l'intensité lumineuse, ou brillance, de chaque point.</span>
<span style="color: #990000; font-style: italic;">// En clair, il s'agit de la trame noire et blanc de l'image.</span>

<span style="color: #990000; font-style: italic;">// Voici les constantes pour la conversion.</span>
<span style="color: #990000; font-style: italic;">// Certaines personnes utilisent les valeurs .299, .587, et .114 du modèle colorimétrique  YIQ.</span>
<span style="color: #990000; font-style: italic;">// Mais Paul Haeberli spécifie bien que les valeurs ci-dessous sont meilleures pour du RGB linéaire.</span>
<span style="color: #0000cc; font-weight: bold;">var</span> rwgt:<span style="color: #0000cc;">Number</span> = .<span style="color: #000000;">3086</span>;
<span style="color: #0000cc; font-weight: bold;">var</span> gwgt:<span style="color: #0000cc;">Number</span> = .<span style="color: #000000;">6094</span>;
<span style="color: #0000cc; font-weight: bold;">var</span> bwgt:<span style="color: #0000cc;">Number</span> = .<span style="color: #000000;">0820</span>;

<span style="color: #990000; font-style: italic;">// Charles A. Poynton conseille (dans le faq colorspace) d'utiliser .212671, .715160 et .072169.</span>

<span style="color: #0000cc; font-weight: bold;">var</span> luminanceTransform:ColorMatrixFilter = <span style="color: #0000cc; font-weight: bold;">new</span> ColorMatrixFilter<span style="color: #000000;">(</span>
	<span style="color: #0000cc; font-weight: bold;">new</span> <span style="color: #0000cc;">Array</span> <span style="color: #000000;">(</span>
	rwgt,   gwgt,   bwgt,   <span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,   <span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,
        rwgt,   gwgt,   bwgt,   <span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,   <span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,
        rwgt,   gwgt,   bwgt,   <span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,   <span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,
        <span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,   	<span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,    <span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,   	<span style="color: #000000;">1</span>.<span style="color: #000000;">0</span>,   <span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>
		<span style="color: #000000;">)</span><span style="color: #000000;">)</span>;

mc.<span style="color: #0000cc;">filters</span> = <span style="color: #000000;">[</span> luminanceTransform <span style="color: #000000;">]</span>;</pre>
<p><ins><strong>-Deuxième exemple à partir de l&#8217;étude d&#8217;Haeberli:</strong></ins></p>
<p><ins><em>Changing Brightness</em></ins><br />
<em>To scale RGB colors a matrix like this is used:</em></p>
<pre>    float mat<span style="color: #000000;">[</span><span style="color: #000000;">4</span><span style="color: #000000;">]</span><span style="color: #000000;">[</span><span style="color: #000000;">4</span><span style="color: #000000;">]</span> = <span style="color: #000000;">{</span>
        rscale, <span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,    <span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,    <span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,
        <span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,    gscale, <span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,    <span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,
        <span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,    <span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,    bscale, <span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,
        <span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,    <span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,    <span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,    <span style="color: #000000;">1</span>.<span style="color: #000000;">0</span>,
    <span style="color: #000000;">}</span>;</pre>
<p><em>Où rscale, gscale, et bscale specifient les valeurs offset à appliquer sur les valeurs RGB. On peut utiliser cette matrice pour modifier la balance des couleurs d&#8217;une image.</em></p>
<p><ins>Ce qui nous donne en ActionScript:</ins></p>
<pre><span style="color: #0000cc;">import</span> flash.<span style="color: #0000cc;">filters</span>.*;

<span style="color: #990000; font-style: italic;">// On utilise directement des valeurs offsets pour ajuster de manière uniforme les valeurs RGB.</span>
<span style="color: #0000cc; font-weight: bold;">function</span> getBrightnessTransform<span style="color: #000000;">(</span> scale:<span style="color: #0000cc;">Number</span> <span style="color: #000000;">)</span> : <span style="color: #0000cc;">Array</span>
<span style="color: #000000;">{</span>
	<span style="color: #0000cc;">return</span> <span style="color: #0000cc; font-weight: bold;">new</span> <span style="color: #0000cc;">Array</span> <span style="color: #000000;">(</span>
	<span style="color: #000000;">1</span>.<span style="color: #000000;">0</span>,	<span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,	<span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,	<span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,   scale,
        <span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,	<span style="color: #000000;">1</span>.<span style="color: #000000;">0</span>,	<span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,	<span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,   scale,
        <span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,	<span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,	<span style="color: #000000;">1</span>.<span style="color: #000000;">0</span>,	<span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,   scale,
        <span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,	<span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,	<span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,	<span style="color: #000000;">1</span>.<span style="color: #000000;">0</span>,   <span style="color: #000000;">0</span>
		<span style="color: #000000;">)</span>;
<span style="color: #000000;">}</span>

mc.<span style="color: #0000cc;">filters</span> = <span style="color: #000000;">[</span> <span style="color: #0000cc; font-weight: bold;">new</span> ColorMatrixFilter<span style="color: #000000;">(</span> getBrightnessTransform<span style="color: #000000;">(</span> <span style="color: #000000;">100</span> <span style="color: #000000;">)</span> <span style="color: #000000;">)</span> <span style="color: #000000;">]</span>;</pre>
<p><ins><strong>-Un dernier exemple pour finir, toujours à partir de l&#8217;étude d&#8217;Haeberli:</strong></ins></p>
<p><ins><em>Modifying Saturation</em></ins><br />
<em>Pour saturer les couleurs RGB, on utilise cette matrice:</em></p>
<pre>     float mat<span style="color: #000000;">[</span><span style="color: #000000;">4</span><span style="color: #000000;">]</span><span style="color: #000000;">[</span><span style="color: #000000;">4</span><span style="color: #000000;">]</span> = <span style="color: #000000;">{</span>
        a,      b,      c,      <span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,
        d,      <span style="color: #0000cc;">e</span>,      f,      <span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,
        g,      h,      i,      <span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,
        <span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,    <span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,    <span style="color: #000000;">0</span>.<span style="color: #000000;">0</span>,    <span style="color: #000000;">1</span>.<span style="color: #000000;">0</span>,
    <span style="color: #000000;">}</span>;</pre>
<p><em>Où les constantes de luminances sont dérivées à partir de la valeur de saturation comme montré ci-dessous:</em></p>
<pre>    a = <span style="color: #000000;">(</span><span style="color: #000000;">1</span>.<span style="color: #000000;">0</span>-s<span style="color: #000000;">)</span>*rwgt + s;
    b = <span style="color: #000000;">(</span><span style="color: #000000;">1</span>.<span style="color: #000000;">0</span>-s<span style="color: #000000;">)</span>*rwgt;
    c = <span style="color: #000000;">(</span><span style="color: #000000;">1</span>.<span style="color: #000000;">0</span>-s<span style="color: #000000;">)</span>*rwgt;
    d = <span style="color: #000000;">(</span><span style="color: #000000;">1</span>.<span style="color: #000000;">0</span>-s<span style="color: #000000;">)</span>*gwgt;
    <span style="color: #0000cc;">e</span> = <span style="color: #000000;">(</span><span style="color: #000000;">1</span>.<span style="color: #000000;">0</span>-s<span style="color: #000000;">)</span>*gwgt + s;
    f = <span style="color: #000000;">(</span><span style="color: #000000;">1</span>.<span style="color: #000000;">0</span>-s<span style="color: #000000;">)</span>*gwgt;
    g = <span style="color: #000000;">(</span><span style="color: #000000;">1</span>.<span style="color: #000000;">0</span>-s<span style="color: #000000;">)</span>*bwgt;
    h = <span style="color: #000000;">(</span><span style="color: #000000;">1</span>.<span style="color: #000000;">0</span>-s<span style="color: #000000;">)</span>*bwgt;
    i = <span style="color: #000000;">(</span><span style="color: #000000;">1</span>.<span style="color: #000000;">0</span>-s<span style="color: #000000;">)</span>*bwgt + s;</pre>
<p><ins>Ce qui nous donne en ActionScript:</ins></p>
<pre><span style="color: #0000cc;">import</span> flash.<span style="color: #0000cc;">filters</span>.*;

<span style="color: #0000cc; font-weight: bold;">var</span> rwgt:<span style="color: #0000cc;">Number</span> = .<span style="color: #000000;">3086</span>;
<span style="color: #0000cc; font-weight: bold;">var</span> gwgt:<span style="color: #0000cc;">Number</span> = .<span style="color: #000000;">6094</span>;
<span style="color: #0000cc; font-weight: bold;">var</span> bwgt:<span style="color: #0000cc;">Number</span> = .<span style="color: #000000;">0820</span>;

<span style="color: #0000cc; font-weight: bold;">function</span> getSaturationTransform <span style="color: #000000;">(</span> sat:<span style="color: #0000cc;">Number</span> <span style="color: #000000;">)</span> : <span style="color: #0000cc;">Array</span>
<span style="color: #000000;">{</span>

	<span style="color: #0000cc; font-weight: bold;">var</span> rl:<span style="color: #0000cc;">Number</span> = rwgt * <span style="color: #000000;">(</span><span style="color: #000000;">1</span> - sat<span style="color: #000000;">)</span>;
	<span style="color: #0000cc; font-weight: bold;">var</span> gl:<span style="color: #0000cc;">Number</span> = gwgt * <span style="color: #000000;">(</span><span style="color: #000000;">1</span> - sat<span style="color: #000000;">)</span>;
	<span style="color: #0000cc; font-weight: bold;">var</span> bl:<span style="color: #0000cc;">Number</span> = bwgt * <span style="color: #000000;">(</span><span style="color: #000000;">1</span> - sat<span style="color: #000000;">)</span>;

	<span style="color: #0000cc;">return</span> <span style="color: #0000cc; font-weight: bold;">new</span> <span style="color: #0000cc;">Array</span> <span style="color: #000000;">(</span>
	rl+sat,	gl,		bl,		<span style="color: #000000;">0</span>,	<span style="color: #000000;">0</span>,
	rl,		gl+sat,	bl,		<span style="color: #000000;">0</span>,	<span style="color: #000000;">0</span>,
	rl,		gl,		bl+sat,	<span style="color: #000000;">0</span>,	<span style="color: #000000;">0</span>,
	<span style="color: #000000;">0</span>,		<span style="color: #000000;">0</span>,		<span style="color: #000000;">0</span>, 		<span style="color: #000000;">1</span>,	<span style="color: #000000;">0</span> <span style="color: #000000;">)</span>;
<span style="color: #000000;">}</span>

mc.<span style="color: #0000cc;">filters</span> = <span style="color: #000000;">[</span> <span style="color: #0000cc; font-weight: bold;">new</span> ColorMatrixFilter<span style="color: #000000;">(</span> getSaturationTransform<span style="color: #000000;">(</span> <span style="color: #000000;">3</span> <span style="color: #000000;">)</span> <span style="color: #000000;">)</span> <span style="color: #000000;">]</span>;</pre>
<p>Pour finir, voici quelques liens:</p>
<ul>
<li><a hreflang="fr" href="http://www.faqs.org/faqs/graphics/colorspace-faq/">Colorspace-faq &#8212; FAQ about Color and Gamma</a> par Charles A. Poynton.</li>
<li><a hreflang="fr" href="http://www.sgi.com/misc/grafica/matrix/">Matrix Operations for Image Processing</a> par Paul Haeberli</li>
<li><a hreflang="fr" href="http://www.kaourantin.net/2005/09/using-flash-player-8-filters-for-good.html">Using Flash Player 8 filters for good</a> par Tinic Uro.</li>
<li><a hreflang="fr" href="http://www.gskinner.com/blog/archives/2005/09/flash_8_source.html">Flash8 source color matrix</a> par Grant Skinner.</li>
<li><a hreflang="fr" href="http://www.quasimondo.com/archives/000565.php">Flash 8: ColorMatrix</a> par Mario Klingemann.</li>
</ul>
<p>J&#8217;espère que ces explications et quelques liens vous donneront envie de passer à l&#8217;action, coder vos propres classes et vous lancer dans des expérimentations graphiques inédites.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tweenpix.net/2005/09/21/colormatrixfilter/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>Design Patterns #4 &#8211; Command Pattern</title>
		<link>http://blog.tweenpix.net/2004/08/15/command-pattern/</link>
		<comments>http://blog.tweenpix.net/2004/08/15/command-pattern/#comments</comments>
		<pubDate>Sun, 15 Aug 2004 17:20:45 +0000</pubDate>
		<dc:creator>Francis Bourre</dc:creator>
				<category><![CDATA[tutorial]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[command]]></category>
		<category><![CDATA[design pattern]]></category>
		<category><![CDATA[tech]]></category>

		<guid isPermaLink="false">http://blog.tweenpix.net/?p=306</guid>
		<description><![CDATA[Aujourd&#8217;hui nous allons aborder le command pattern. Ce modèle de conception est assez intuitif. Il s&#8217;agit d&#8217;encapsuler à l&#8217;intérieur d&#8217;un objet (plus communément appellé commande) le déroulement d&#8217;une action. A chaque fois que je voudrais exécuter cette action à l&#8217;intérieur d&#8217;une application, il me suffira d&#8217;appeller la méthode execute() de mon objet commande. Commençons par [...]]]></description>
			<content:encoded><![CDATA[<p>Aujourd&#8217;hui nous allons aborder le command pattern.</p>
<p>Ce modèle de conception est assez intuitif. Il s&#8217;agit d&#8217;encapsuler à l&#8217;intérieur d&#8217;un objet (plus communément appellé commande) le déroulement d&#8217;une action. A chaque fois que je voudrais exécuter cette action à l&#8217;intérieur d&#8217;une application, il me suffira d&#8217;appeller la méthode execute() de mon objet commande.</p>
<p>Commençons par un exemple basique :</p>
<pre><span style="color: #0000cc; font-weight: bold;">class</span> RebootCommand
<span style="color: #000000;">{</span>
 	<span style="color: #0000cc;">public</span> <span style="color: #0000cc; font-weight: bold;">function</span> execute<span style="color: #000000;">(</span><span style="color: #000000;">)</span> : <span style="color: #0000cc;">Void</span>
 	<span style="color: #000000;">{</span>
  		<span style="color: #0000cc;">trace</span><span style="color: #000000;">(</span><span style="color: #006600;">"reboot my PC"</span><span style="color: #000000;">)</span>;
  	<span style="color: #000000;">}</span>
<span style="color: #000000;">}</span></pre>
<pre><span style="color: #0000cc;">import</span> RebootCommand;

<span style="color: #0000cc; font-weight: bold;">var</span> oReboot:RebootCommand = <span style="color: #0000cc; font-weight: bold;">new</span> RebootCommand<span style="color: #000000;">(</span><span style="color: #000000;">)</span>;
oReboot.<span style="color: #0000cc;">execute</span><span style="color: #000000;">(</span><span style="color: #000000;">)</span>;</pre>
<p>La classe <em>RebootCommand</em> une fois instanciée me permet de rebooter mon ordinateur à chaque appel de sa méthode execute.</p>
<p>A partir de ce postulat, il devient évident que pour pouvoir être exécutée, une commande doit obligatoirement implémenter une méthode execute. Cette méthode contiendra les éléments nécéssaires au bon déroulement de l&#8217;action sollicitée.</p>
<p>Par conséquent, une commande devra obligatoirement implémenter l&#8217;interface suivante :</p>
<pre><span style="color: #0000cc;">interface</span> Command
<span style="color: #000000;">{</span>
 	<span style="color: #0000cc;">public</span> <span style="color: #0000cc; font-weight: bold;">function</span> execute<span style="color: #000000;">(</span><span style="color: #000000;">)</span> : <span style="color: #0000cc;">Void</span>;
<span style="color: #000000;">}</span></pre>
<p>Reprenons maintenant le même exemple en utilisant l&#8217;interface ci-dessus :</p>
<pre><span style="color: #0000cc;">import</span> Command;

<span style="color: #0000cc; font-weight: bold;">class</span> RebootCommand <span style="color: #0000cc;">implements</span> Command
<span style="color: #000000;">{</span>
 	<span style="color: #0000cc;">public</span> <span style="color: #0000cc; font-weight: bold;">function</span> execute<span style="color: #000000;">(</span><span style="color: #000000;">)</span> : <span style="color: #0000cc;">Void</span>
 	<span style="color: #000000;">{</span>
  		<span style="color: #0000cc;">trace</span><span style="color: #000000;">(</span><span style="color: #006600;">"reboot my PC"</span><span style="color: #000000;">)</span>;
  	<span style="color: #000000;">}</span>
<span style="color: #000000;">}</span></pre>
<p>L&#8217;utilisation de l&#8217;interface Command : &#8211; Garantit que ma commande possède bien une méthode execute pour être déployée. &#8211; Permet (comme nous le verrons plus tard) de recourir au polymorphisme pour exécuter des commandes diverses sans se soucier de leur implémentation concrète.</p>
<p>Point essentiel et souvent controversé, la méthode execute ne renvoit rien mais <ins>SURTOUT</ins> n&#8217;autorise aucun paramètre. En effet, une commande, au moment de son exécution est censée déjà détenir les éléments nécessaires pour pouvoir interagir avec le système.</p>
<p>De prime abord, cela peut paraître un peu rigide et vous devez vous demander comment procéder pour spécifier des interactions avec le coeur de l&#8217;application ?</p>
<p>Il suffit tout simplement d&#8217;utiliser le constructeur de votre classe concrète pour pouvoir stocker les propriétés qui seront nécessaires au moment de l&#8217;exécution.</p>
<p>Prenons un deuxième exemple pour illustrer ceci :</p>
<pre><span style="color: #0000cc;">import</span> Command;

<span style="color: #0000cc; font-weight: bold;">class</span> DisplayDateCommand <span style="color: #0000cc;">implements</span> Command
<span style="color: #000000;">{</span>
 	<span style="color: #0000cc;">private</span> <span style="color: #0000cc; font-weight: bold;">var</span> _tViewHelper:<span style="color: #0000cc;">TextField</span>;

 	<span style="color: #0000cc;">public</span> <span style="color: #0000cc; font-weight: bold;">function</span> DisplayDateCommand<span style="color: #000000;">(</span>tViewHelper:<span style="color: #0000cc;">TextField</span><span style="color: #000000;">)</span>
 	<span style="color: #000000;">{</span>
  		_tViewHelper = tViewHelper;
  	<span style="color: #000000;">}</span>

 	<span style="color: #0000cc;">public</span> <span style="color: #0000cc; font-weight: bold;">function</span> execute<span style="color: #000000;">(</span><span style="color: #000000;">)</span> : <span style="color: #0000cc;">Void</span>
 	<span style="color: #000000;">{</span>
  		_tViewHelper.<span style="color: #0000cc;">text</span> = <span style="color: #0000cc;">String</span><span style="color: #000000;">(</span><span style="color: #0000cc; font-weight: bold;">new</span> <span style="color: #0000cc;">Date</span><span style="color: #000000;">(</span><span style="color: #000000;">)</span><span style="color: #000000;">)</span>;
  	<span style="color: #000000;">}</span>
<span style="color: #000000;">}</span>	<span style="color: #000000;">}</span>
<span style="color: #000000;">}</span></pre>
<p>Dans l&#8217;exemple ci-dessus on utilise un helper en paramètre dans le constructeur pour spécifier la cible graphique qui affichera la date du jour.</p>
<p>Il est biensûr possible d&#8217;ajouter des accesseurs dans votre classe concrète pour pouvoir modifier à tout moment les propriétés requises pour l&#8217;exécution de votre commande :</p>
<pre><span style="color: #0000cc;">import</span> Command;

<span style="color: #0000cc; font-weight: bold;">class</span> DisplayDateCommand <span style="color: #0000cc;">implements</span> Command
<span style="color: #000000;">{</span>
 	<span style="color: #0000cc;">private</span> <span style="color: #0000cc; font-weight: bold;">var</span> _tViewHelper:<span style="color: #0000cc;">TextField</span>;

 	<span style="color: #0000cc;">public</span> <span style="color: #0000cc; font-weight: bold;">function</span> DisplayDateCommand<span style="color: #000000;">(</span>tViewHelper:<span style="color: #0000cc;">TextField</span><span style="color: #000000;">)</span>
 	<span style="color: #000000;">{</span>
  		_tViewHelper = tViewHelper;
  	<span style="color: #000000;">}</span>

 	<span style="color: #0000cc;">public</span> <span style="color: #0000cc; font-weight: bold;">function</span> execute<span style="color: #000000;">(</span><span style="color: #000000;">)</span> : <span style="color: #0000cc;">Void</span>
 	<span style="color: #000000;">{</span>
  		_tViewHelper.<span style="color: #0000cc;">text</span> = <span style="color: #0000cc;">String</span><span style="color: #000000;">(</span><span style="color: #0000cc; font-weight: bold;">new</span> <span style="color: #0000cc;">Date</span><span style="color: #000000;">(</span><span style="color: #000000;">)</span><span style="color: #000000;">)</span>;
  	<span style="color: #000000;">}</span>

 	<span style="color: #0000cc;">public</span> <span style="color: #0000cc; font-weight: bold;">function</span> setViewHelper<span style="color: #000000;">(</span>tViewHelper:<span style="color: #0000cc;">TextField</span><span style="color: #000000;">)</span> : <span style="color: #0000cc;">Void</span>
 	<span style="color: #000000;">{</span>
  		_tViewHelper = tViewHelper;
  	<span style="color: #000000;">}</span>
<span style="color: #000000;">}</span></pre>
<pre><span style="color: #0000cc;">import</span> DisplayDateCommand;

<span style="color: #0000cc;">this</span>.<span style="color: #0000cc;">createTextField</span><span style="color: #000000;">(</span><span style="color: #006600;">"__txt"</span>, <span style="color: #000000;">1</span>, <span style="color: #000000;">30</span>, <span style="color: #000000;">30</span>, <span style="color: #000000;">200</span>, <span style="color: #000000;">20</span><span style="color: #000000;">)</span>;
<span style="color: #0000cc; font-weight: bold;">var</span> ddc:DisplayDateCommand = <span style="color: #0000cc; font-weight: bold;">new</span> DisplayDateCommand<span style="color: #000000;">(</span><span style="color: #000000;">)</span>;
ddc.<span style="color: #0000cc;">setViewHelper</span><span style="color: #000000;">(</span><span style="color: #0000cc;">this</span>.__txt<span style="color: #000000;">)</span>;
ddc.<span style="color: #0000cc;">execute</span><span style="color: #000000;">(</span><span style="color: #000000;">)</span>;</pre>
<p>Maintenant, passons à la question phare, celle que vous êtes tous en droit de vous poser : Quel est l&#8217;intérêt de ce modèle de conception ?</p>
<p>L&#8217;intérêt majeur, c&#8217;est de pouvoir découpler l&#8217;objet qui crée une requête pour une action donnée et l&#8217;action elle-même ou le receveur de celle-ci. L&#8217;exemple récurrent pour illustrer ce concept, c&#8217;est l&#8217;utilisation d&#8217;UIs (interfaces utilisateur) à l&#8217;interieur d&#8217;une application. Une interface utilisateur est censée ignorer l&#8217;implémentation et le déroulement des requêtes qu&#8217;elle formule. Autrement dit, le code des requêtes doit donc en aucun cas être exposé à celle-ci. On préférera l&#8217;encapsuler à l&#8217;intérieur de commandes, classes concrètes implémentant la classe abstraite Command (interface Command en AS2.0). Les UIs n&#8217;auront plus qu&#8217;à invoquer les commandes disponibles pour obtenir satisfaction à leurs requêtes.</p>
<pre><span style="color: #0000cc;">import</span> DisplayDateCommand;
<span style="color: #0000cc;">import</span> mx.<span style="color: #0000cc;">controls</span>.<span style="color: #0000cc;">Button</span>;

<span style="color: #0000cc;">this</span>.<span style="color: #0000cc;">createTextField</span><span style="color: #000000;">(</span><span style="color: #006600;">"__txt"</span>, <span style="color: #000000;">2</span>, <span style="color: #000000;">30</span>, <span style="color: #000000;">30</span>, <span style="color: #000000;">200</span>, <span style="color: #000000;">20</span><span style="color: #000000;">)</span>;
<span style="color: #0000cc; font-weight: bold;">var</span> tDisplay:<span style="color: #0000cc;">TextField</span> = <span style="color: #0000cc;">this</span>.__txt;

<span style="color: #0000cc; font-weight: bold;">var</span> oDdC:DisplayDateCommand = <span style="color: #0000cc; font-weight: bold;">new</span> DisplayDateCommand<span style="color: #000000;">(</span><span style="color: #000000;">)</span>;
oDdC.<span style="color: #0000cc;">setViewHelper</span><span style="color: #000000;">(</span>tDisplay<span style="color: #000000;">)</span>;

<span style="color: #0000cc; font-weight: bold;">var</span> pbGetDate:<span style="color: #0000cc;">Button</span> = <span style="color: #0000cc;">this</span>.<span style="color: #0000cc;">createClassObject</span><span style="color: #000000;">(</span><span style="color: #0000cc;">Button</span>, <span style="color: #006600;">"__pbGetDate"</span>, <span style="color: #000000;">1</span><span style="color: #000000;">)</span>;
pbGetDate.<span style="color: #0000cc;">move</span><span style="color: #000000;">(</span><span style="color: #000000;">30</span>, <span style="color: #000000;">60</span><span style="color: #000000;">)</span>;
pbGetDate.<span style="color: #0000cc;">label</span> = <span style="color: #006600;">"Display"</span>;
pbGetDate.<span style="color: #0000cc;">addEventListener</span><span style="color: #000000;">(</span><span style="color: #006600;">"click"</span>, <span style="color: #0000cc;">this</span><span style="color: #000000;">)</span>;

<span style="color: #0000cc; font-weight: bold;">function</span> click<span style="color: #000000;">(</span><span style="color: #000000;">)</span> : <span style="color: #0000cc;">Void</span>
<span style="color: #000000;">{</span>
 	oDdC.<span style="color: #0000cc;">execute</span><span style="color: #000000;">(</span><span style="color: #000000;">)</span>;
<span style="color: #000000;">}</span></pre>
<p>Deuxième aspect non négligeable, c&#8217;est la possibilité d&#8217;atomiser les fonctionnalités d&#8217;une application en objets indépendants pour ne pas surcharger le contrôleur d&#8217;une application. On constatera par expérience que niveau design, il est toujours plus facile et élégant de changer par exemple l&#8217;implémentation d&#8217;une commande SeConnecter à l&#8217;intérieur d&#8217;une classe dédiée que de parcourir 2.000 lignes de code d&#8217;un contrôleur pour modifier celle-ci.</p>
<p>L&#8217;atomisation des fonctionnalités peut permettre aussi de créer des classes composites pour définir des macro-commandes (enchaînement de plusieurs commandes).</p>
<pre><span style="color: #0000cc;">import</span> Command;

<span style="color: #0000cc;">interface</span> MacroCommand <span style="color: #0000cc;">extends</span> Command
<span style="color: #000000;">{</span>
 	<span style="color: #0000cc;">public</span> <span style="color: #0000cc; font-weight: bold;">function</span> addCommand<span style="color: #000000;">(</span>oCommand:Command<span style="color: #000000;">)</span> : <span style="color: #0000cc;">Void</span>;
<span style="color: #000000;">}</span></pre>
<pre><span style="color: #0000cc;">import</span> MacroCommand;

<span style="color: #0000cc; font-weight: bold;">class</span> MyMacroCommand <span style="color: #0000cc;">implements</span> MacroCommand
<span style="color: #000000;">{</span>
 	<span style="color: #0000cc;">private</span> <span style="color: #0000cc; font-weight: bold;">var</span> _aCommands:<span style="color: #0000cc;">Array</span>;

 	<span style="color: #0000cc;">public</span> <span style="color: #0000cc; font-weight: bold;">function</span> MyMacroCommand<span style="color: #000000;">(</span><span style="color: #000000;">)</span>
 	<span style="color: #000000;">{</span>
  		_aCommands = <span style="color: #0000cc; font-weight: bold;">new</span> <span style="color: #0000cc;">Array</span><span style="color: #000000;">(</span><span style="color: #000000;">)</span>;
  	<span style="color: #000000;">}</span>

 	<span style="color: #0000cc;">public</span> <span style="color: #0000cc; font-weight: bold;">function</span> addCommand<span style="color: #000000;">(</span>oCommand:Command<span style="color: #000000;">)</span> : <span style="color: #0000cc;">Void</span>
 	<span style="color: #000000;">{</span>
  		_aCommands.<span style="color: #0000cc;">push</span><span style="color: #000000;">(</span>oCommand<span style="color: #000000;">)</span>;
  	<span style="color: #000000;">}</span>

 	<span style="color: #0000cc;">public</span> <span style="color: #0000cc; font-weight: bold;">function</span> execute<span style="color: #000000;">(</span><span style="color: #000000;">)</span> : <span style="color: #0000cc;">Void</span>
 	<span style="color: #000000;">{</span>
  		<span style="color: #0000cc; font-weight: bold;">var</span> l:<span style="color: #0000cc;">Number</span> = _aCommands.<span style="color: #0000cc;">length</span>;
  		<span style="color: #0000cc;">for</span> <span style="color: #000000;">(</span><span style="color: #0000cc; font-weight: bold;">var</span> i:<span style="color: #0000cc;">Number</span> = <span style="color: #000000;">0</span>; i&lt;l; i++<span style="color: #000000;">)</span> _aCommands<span style="color: #000000;">[</span>i<span style="color: #000000;">]</span>.<span style="color: #0000cc;">execute</span><span style="color: #000000;">(</span><span style="color: #000000;">)</span>;
  	<span style="color: #000000;">}</span>
<span style="color: #000000;">}</span></pre>
<pre><span style="color: #0000cc;">import</span> MyMacroCommand;
<span style="color: #0000cc;">import</span> RebootCommand;
<span style="color: #0000cc;">import</span> DisplayDateCommand;

<span style="color: #0000cc;">this</span>.<span style="color: #0000cc;">createTextField</span><span style="color: #000000;">(</span><span style="color: #006600;">"__txt"</span>, <span style="color: #000000;">2</span>, <span style="color: #000000;">30</span>, <span style="color: #000000;">30</span>, <span style="color: #000000;">200</span>, <span style="color: #000000;">20</span><span style="color: #000000;">)</span>;

<span style="color: #0000cc; font-weight: bold;">var</span> oMMC:MyMacroCommand = <span style="color: #0000cc; font-weight: bold;">new</span> MyMacroCommand<span style="color: #000000;">(</span><span style="color: #000000;">)</span>;
oMMC.<span style="color: #0000cc;">addCommand</span><span style="color: #000000;">(</span> <span style="color: #0000cc; font-weight: bold;">new</span> RebootCommand<span style="color: #000000;">(</span><span style="color: #000000;">)</span> <span style="color: #000000;">)</span>;
oMMC.<span style="color: #0000cc;">addCommand</span><span style="color: #000000;">(</span> <span style="color: #0000cc; font-weight: bold;">new</span> DisplayDateCommand<span style="color: #000000;">(</span><span style="color: #0000cc;">this</span>.__txt<span style="color: #000000;">)</span> <span style="color: #000000;">)</span>;

oMMC.<span style="color: #0000cc;">execute</span><span style="color: #000000;">(</span><span style="color: #000000;">)</span>;</pre>
<p><em>addCommand</em> utilise le polymorphisme d&#8217;interface que j&#8217;évoquais au début de cet article. Cette méthode attend en paramètre un objet de la famille Command, la nature exacte de celui-ci lui importe peu.</p>
<p>Le dernier aspect est le plus intéressant à mon goût. Il s&#8217;agit de déployer le command pattern à l&#8217;intérieur d&#8217;un front controller pour gagner en souplesse lors du développement et la maintenance d&#8217;une application.</p>
<p>Ceci sera le sujet du prochain volet. <img src='http://blog.tweenpix.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Voici pour finir une fiche technique résumant les caractéristiques du modèle <strong>Command</strong> :</p>
<p><strong>Nom</strong> : Command pattern<br />
<strong>Le problème</strong> :<br />
Découpler les objets qui invoquent une action de ceux qui l&#8217;exécutent.<br />
<strong>La solution</strong> :<br />
Créer une classe abstraite Command (interface) avec une méthode execute. Chaque commande (action) d&#8217;une application sera une classe concrète implémentant la méthode virtuelle execute. Les objets qui en feront la requête n&#8217;auront plus qu&#8217;à trigger celle-ci sans en connaître l&#8217;implémentation<br />
<strong>Les conséquences</strong> :<br />
- Le command pattern éradique tout couplage potentiel entre l&#8217;objet qui invoque une opération et celui qui sait comment la réaliser.<br />
- Une commande est un objet à part entière. Elle peut être manipulée, voire même étendue comme bon vous semble.<br />
- On peut créer des commandes composites (cf: MacroCommand).<br />
- Les commandes peuvent offrir la possibilité de faire et défaire (undo et niveaux d&#8217;undos).<br />
- Les commandes jugulées à un front-controller offrent à une application une souplesse et une capacité de maintenance indéniables.</p>
<p>Les fichiers sources sont disponibles <a hreflang="fr" href="http://www.tweenpix.net/files/commandpattern.rar">ici</a>.</p>
<p>Voilà, cet article touche à sa fin. J&#8217;ai tenté plus ou moins adroitement de vulgariser ce modèle de conception et de l&#8217;illustrer avec des exemples qui restent le plus simple possible afin que tout le monde puisse y trouve son compte. La suite bientôt, avec au programme quelques notions un peu plus avancées cette fois-ci : Création d&#8217;un <strong>Front Controller</strong> déployant le <strong>Command</strong> pattern avec <strong>ViewHelper</strong> à l&#8217;appui.</p>
<p>Il est possible qu&#8217;entre temps je vous fasse d&#8217;abord faire un petit détour par le modèle <strong>Observer</strong> et vous propose une manière qui me semple plus adéquate pour gérer les événements en AS 2.0 que celle proposée par EventDispatcher. (Avis 100% subjectif bien entendu) En effet, la force d<em>&#8216;EventDispatcher</em> c&#8217;est sa souplesse, mais c&#8217;est malheureusement aussi son talon d&#8217;achille. Je déplore son typage faible, son incapacité à scinder les écouteurs en plusieurs groupes (statique oblige) et l&#8217;impossibilité de savoir si pour un événement donné un ou plusieurs objets sont abonnés. Ce sera l&#8217;occasion pour moi de vous faire découvrir une autre façon de travailler avec les événements (plus rigide) et vous faire partager le package com.bourre.events de <a hreflang="fr" href="http://www.pixlib.org">pixLib</a> en avant-première.</p>
<p>En attendant n&#8217;hésitez pas à me faire partager vos éventuelles questions ou commentaires.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tweenpix.net/2004/08/15/command-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Design Patterns #3 &#8211; Abstract Factory</title>
		<link>http://blog.tweenpix.net/2004/04/20/design-patterns-3-abstract-factory/</link>
		<comments>http://blog.tweenpix.net/2004/04/20/design-patterns-3-abstract-factory/#comments</comments>
		<pubDate>Tue, 20 Apr 2004 18:47:24 +0000</pubDate>
		<dc:creator>Francis Bourre</dc:creator>
				<category><![CDATA[tech]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[abstract factory]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[design pattern]]></category>

		<guid isPermaLink="false">http://blog.tweenpix.net/?p=649</guid>
		<description><![CDATA[La dernière fois, nous avons abordé les classe abstraites et je vous ai proposé une implémentation possible en AS 2.0 pour contourner l’absence du mot-clef abstract. Petit rappel de rigueur, créer une classe abstraite, c’est définir une classe mère non instantiable qui décrit les comportements génériques de classes plus spécialisées, les classes concrètes. Aujourd’hui, nous [...]]]></description>
			<content:encoded><![CDATA[<p>La dernière fois, nous avons abordé les classe abstraites et je vous ai<br />
proposé une implémentation possible en AS 2.0 pour contourner l’absence<br />
du mot-clef <em>abstract</em>.</p>
<p>Petit rappel de rigueur, créer une classe abstraite, c’est définir<br />
une classe mère non instantiable qui décrit les comportements<br />
génériques de classes plus spécialisées, les classes concrètes.</p>
<p>Aujourd’hui, nous allons étudier le modèle fabrique abstraite, en<br />
nous servant des notions acquises lors des deux précédents<br />
volets&nbsp;: <a href="http://tweenpix.net/blog/?p=122" hreflang="fr">Singleton</a> et <a href="http://tweenpix.net/blog/?p=131" hreflang="fr">abstract</a>.</p>
<p>Entrons tout de suite dans le vif du sujet !</p>
<p>L’intérêt de la fabrique abstraite, c’est de proposer une interface<br />
pour créer des familles d’objet sans avoir à manipuler directement<br />
leurs classes concrètes.</p>
<p>Quand dois-je avoir recours à ce pattern&nbsp;? Quand je veux<br />
pouvoir utiliser une famille d’objets et pouvoir la substituer à tout<br />
moment par une autre à l’intérieur de mon application.</p>
<p>Mais qu’est-ce qu’une fabrique&nbsp;? Une fabrique, c’est une classe<br />
permettant de créer des instances d’une classe ou d’un set de classes.<br />
Son rôle est d’encapsuler la création des dites instances et de servir<br />
(le plus souvent) de référence globale pour la création de celles-ci en<br />
deployant le pattern Singleton.</p>
<p>Pour illustrer ce concept, j’ai repris l’exemple cliché souvent<br />
associé à ce pattern, créer deux famille de widgets et offrir à tout<br />
moment la possibilité de remplacer l’une par l’autre. Mais rien ne vous<br />
interdit de l’appliquer à des domaines totalement différents. Quelques<br />
exemples divers&nbsp;: &#8211; Génération des éléments d’un jeu avec des<br />
familles d’objets classées par niveaux de difficulté ou par univers. -<br />
Création d’un environnement skinnable. &#8211; Réalisation d’un framework<br />
modulable avec des familles d’objets liées à certaines utilisations<br />
spécifiques. …</p>
<p>Le principe fondamental, c’est de créer une classe abstraite listant<br />
les méthodes communes à chaque fabrique. Ces méthodes une fois<br />
implémentées dans les fabriques concrètes (fabrique de chaque famille)<br />
permettront d’instancier chaque type d’objet spécifique.</p>
<pre><span style="font-style: italic; color: rgb(153, 0, 0);">// UIsFactory.as</span>

<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">ScrollBar</span>;
<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">Container</span>;
<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">MenuBox</span>;

<span style="font-weight: bold; color: rgb(0, 0, 204);">class</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">UIsFactory</span>
<span style="color: rgb(0, 0, 0);">{</span>
 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">var</span> createScrollBar:<span style="font-weight: bold; color: rgb(0, 0, 204);">Function</span>;
 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">var</span> createContainer:<span style="font-weight: bold; color: rgb(0, 0, 204);">Function</span>;
 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">var</span> createMenuBox:<span style="font-weight: bold; color: rgb(0, 0, 204);">Function</span>;

 	<span style="color: rgb(0, 0, 204);">private</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> UIsFactory<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> <span style="color: rgb(0, 0, 0);">{</span><span style="color: rgb(0, 0, 0);">}</span>

<span style="color: rgb(0, 0, 0);">}</span></pre>
<pre><span style="font-style: italic; color: rgb(153, 0, 0);">// UIsFactoryMethods.as</span>

<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">ScrollBar</span>;
<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">Container</span>;

<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">MenuBox</span>;

<span style="color: rgb(0, 0, 204);">interface</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">UIsFactoryMethods</span>
<span style="color: rgb(0, 0, 0);">{</span>
 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> createScrollBar<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : ScrollBar;
 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> createContainer<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : Container;
 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> createMenuBox<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : MenuBox;

<span style="color: rgb(0, 0, 0);">}</span></pre>
<p>Les objets sont donc pour l’instant abstraits eux aussi. Ceci nous<br />
permettra plus tard de spécialiser chacun d’eux en corrélation avec la<br />
famille à laquelle ils appartiennent.</p>
<pre><span style="font-style: italic; color: rgb(153, 0, 0);">// ScrollBar.as</span>

<span style="font-weight: bold; color: rgb(0, 0, 204);">class</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">ScrollBar</span>
<span style="color: rgb(0, 0, 0);">{</span>
 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">var</span> <span style="color: rgb(0, 0, 204);">scroll</span>:<span style="font-weight: bold; color: rgb(0, 0, 204);">Function</span>;

 	<span style="color: rgb(0, 0, 204);">private</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> ScrollBar<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> <span style="color: rgb(0, 0, 0);">{</span><span style="color: rgb(0, 0, 0);">}</span>

<span style="color: rgb(0, 0, 0);">}</span></pre>
<pre><span style="font-style: italic; color: rgb(153, 0, 0);">// ScrollBarMethods.as</span>

<span style="color: rgb(0, 0, 204);">interface</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">ScrollBarMethods</span>
<span style="color: rgb(0, 0, 0);">{</span>
 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> <span style="color: rgb(0, 0, 204);">scroll</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : <span style="color: rgb(0, 0, 204);">Void</span>;

<span style="color: rgb(0, 0, 0);">}</span></pre>
<pre><span style="font-style: italic; color: rgb(153, 0, 0);">// Container.as</span>

<span style="font-weight: bold; color: rgb(0, 0, 204);">class</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">Container</span>
<span style="color: rgb(0, 0, 0);">{</span>
 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">var</span> empty:<span style="font-weight: bold; color: rgb(0, 0, 204);">Function</span>;

 	<span style="color: rgb(0, 0, 204);">private</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> Container<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> <span style="color: rgb(0, 0, 0);">{</span><span style="color: rgb(0, 0, 0);">}</span>

<span style="color: rgb(0, 0, 0);">}</span></pre>
<pre><span style="font-style: italic; color: rgb(153, 0, 0);">// ContainerMethods.as</span>

<span style="color: rgb(0, 0, 204);">interface</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">ContainerMethods</span>
<span style="color: rgb(0, 0, 0);">{</span>
 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> empty<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : <span style="color: rgb(0, 0, 204);">Void</span>;

<span style="color: rgb(0, 0, 0);">}</span></pre>
<pre><span style="font-style: italic; color: rgb(153, 0, 0);">// MenuBox.as</span>

<span style="font-weight: bold; color: rgb(0, 0, 204);">class</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">MenuBox</span>
<span style="color: rgb(0, 0, 0);">{</span>
 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">var</span> display:<span style="font-weight: bold; color: rgb(0, 0, 204);">Function</span>;

 	<span style="color: rgb(0, 0, 204);">private</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> MenuBox<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> <span style="color: rgb(0, 0, 0);">{</span><span style="color: rgb(0, 0, 0);">}</span>

<span style="color: rgb(0, 0, 0);">}</span></pre>
<pre><span style="font-style: italic; color: rgb(153, 0, 0);">// MenuBoxMethods.as</span>

<span style="color: rgb(0, 0, 204);">interface</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">MenuBoxMethods</span>
<span style="color: rgb(0, 0, 0);">{</span>
 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> display<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : <span style="color: rgb(0, 0, 204);">Void</span>;

<span style="color: rgb(0, 0, 0);">}</span></pre>
<p>Je peux donc maintenant créer mes deux familles, Rebound et Water,<br />
avec pour chacune d’elle, une fabrique concrète me permettant<br />
d’instancier mes widgets.</p>
<pre><span style="font-style: italic; color: rgb(153, 0, 0);">// ReboundUIsFactory.as</span>

<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">UIsFactory</span>;
<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">UIsFactoryMethods</span>;

<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">ScrollBar</span>;
<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">Container</span>;
<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">MenuBox</span>;

<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">elastic</span>.<span style="color: rgb(0, 0, 204);">ElasticScrollBar</span>;
<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">elastic</span>.<span style="color: rgb(0, 0, 204);">ElasticContainer</span>;
<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">elastic</span>.<span style="color: rgb(0, 0, 204);">ElasticMenuBox</span>;

<span style="font-weight: bold; color: rgb(0, 0, 204);">class</span> factory.<span style="color: rgb(0, 0, 204);">ReboundUIsFactory</span> <span style="color: rgb(0, 0, 204);">extends</span> UIsFactory <span style="color: rgb(0, 0, 204);">implements</span> UIsFactoryMethods
<span style="color: rgb(0, 0, 0);">{</span>
 	<span style="color: rgb(0, 0, 204);">private</span> <span style="color: rgb(0, 0, 204);">static</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">var</span> _oInstance = <span style="font-weight: bold; color: rgb(0, 0, 204);">new</span> ReboundUIsFactory<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span>;
 	<span style="color: rgb(0, 0, 204);">private</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> ReboundUIsFactory<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> <span style="color: rgb(0, 0, 0);">{</span><span style="color: rgb(0, 0, 0);">}</span>

 	<span style="color: rgb(0, 0, 204);">public</span> <span style="color: rgb(0, 0, 204);">static</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> getInstance<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : ReboundUIsFactory <span style="color: rgb(0, 0, 0);">{</span> <span style="color: rgb(0, 0, 204);">return</span> _oInstance; <span style="color: rgb(0, 0, 0);">}</span>

 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> createScrollBar<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : ScrollBar
 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">return</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">new</span> ElasticScrollBar<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> createContainer<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : Container
 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">return</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">new</span> ElasticContainer<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> createMenuBox<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : MenuBox
 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">return</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">new</span> ElasticMenuBox<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

<span style="color: rgb(0, 0, 0);">}</span></pre>
<pre><span style="font-style: italic; color: rgb(153, 0, 0);">//WaterUIsFactory.as</span>

<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">UIsFactory</span>;
<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">UIsFactoryMethods</span>;

<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">ScrollBar</span>;
<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">Container</span>;
<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">MenuBox</span>;

<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">liquid</span>.<span style="color: rgb(0, 0, 204);">LiquidScrollBar</span>;
<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">liquid</span>.<span style="color: rgb(0, 0, 204);">LiquidContainer</span>;
<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">classic</span>.<span style="color: rgb(0, 0, 204);">ClassicMenuBox</span>;

<span style="font-weight: bold; color: rgb(0, 0, 204);">class</span> factory.<span style="color: rgb(0, 0, 204);">WaterUIsFactory</span> <span style="color: rgb(0, 0, 204);">extends</span> UIsFactory <span style="color: rgb(0, 0, 204);">implements</span> UIsFactoryMethods
<span style="color: rgb(0, 0, 0);">{</span>
 	<span style="color: rgb(0, 0, 204);">private</span> <span style="color: rgb(0, 0, 204);">static</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">var</span> _oInstance = <span style="font-weight: bold; color: rgb(0, 0, 204);">new</span> WaterUIsFactory<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span>;
 	<span style="color: rgb(0, 0, 204);">private</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> WaterUIsFactory<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> <span style="color: rgb(0, 0, 0);">{</span><span style="color: rgb(0, 0, 0);">}</span>

 	<span style="color: rgb(0, 0, 204);">public</span> <span style="color: rgb(0, 0, 204);">static</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> getInstance<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : WaterUIsFactory <span style="color: rgb(0, 0, 0);">{</span> <span style="color: rgb(0, 0, 204);">return</span> _oInstance; <span style="color: rgb(0, 0, 0);">}</span>

 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> createScrollBar<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : ScrollBar
 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">return</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">new</span> LiquidScrollBar<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> createContainer<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : Container
 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">return</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">new</span> LiquidContainer<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> createMenuBox<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : MenuBox
 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">return</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">new</span> ClassicMenuBox<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

<span style="color: rgb(0, 0, 0);">}</span></pre>
<p>On remarquera au passage qu’il est facile de modifier le contenu de<br />
chacune des familles, vu que les composants sont tous abstraits. Encore<br />
un des bénéfices de l’abstract. ^^</p>
<p>Voici les classes concrètes des objets instanciés à partir des deux fabriques (familles virtuelles)&nbsp;:</p>
<pre><span style="font-style: italic; color: rgb(153, 0, 0);">// ClassicMenuBox.as</span>

<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">MenuBox</span>;

<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">MenuBoxMethods</span>;

<span style="font-weight: bold; color: rgb(0, 0, 204);">class</span> factory.<span style="color: rgb(0, 0, 204);">classic</span>.<span style="color: rgb(0, 0, 204);">ClassicMenuBox</span> <span style="color: rgb(0, 0, 204);">extends</span> MenuBox <span style="color: rgb(0, 0, 204);">implements</span> MenuBoxMethods

<span style="color: rgb(0, 0, 0);">{</span>
 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> ClassicMenuBox<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span>
 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">trace</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 204);">this</span> + <span style="color: rgb(0, 102, 0);">" was created"</span><span style="color: rgb(0, 0, 0);">)</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> display<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : <span style="color: rgb(0, 0, 204);">Void</span>
 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">trace</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 204);">this</span> + <span style="color: rgb(0, 102, 0);">" display()"</span><span style="color: rgb(0, 0, 0);">)</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> <span style="color: rgb(0, 0, 204);">toString</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : <span style="color: rgb(0, 0, 204);">String</span>
 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">return</span> <span style="color: rgb(0, 102, 0);">"ClassicMenuBox"</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

<span style="color: rgb(0, 0, 0);">}</span></pre>
<pre><span style="font-style: italic; color: rgb(153, 0, 0);">// ElasticContainer.as</span>

<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">Container</span>;
<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">ContainerMethods</span>;

<span style="font-weight: bold; color: rgb(0, 0, 204);">class</span> factory.<span style="color: rgb(0, 0, 204);">elastic</span>.<span style="color: rgb(0, 0, 204);">ElasticContainer</span> <span style="color: rgb(0, 0, 204);">extends</span> Container <span style="color: rgb(0, 0, 204);">implements</span> ContainerMethods
<span style="color: rgb(0, 0, 0);">{</span>
 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> ElasticContainer<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span>

 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">trace</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 204);">this</span> + <span style="color: rgb(0, 102, 0);">" was created"</span><span style="color: rgb(0, 0, 0);">)</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> empty<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : <span style="color: rgb(0, 0, 204);">Void</span>

 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">trace</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 204);">this</span> + <span style="color: rgb(0, 102, 0);">" empty()"</span><span style="color: rgb(0, 0, 0);">)</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> <span style="color: rgb(0, 0, 204);">toString</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : <span style="color: rgb(0, 0, 204);">String</span>

 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">return</span> <span style="color: rgb(0, 102, 0);">"ElasticContainer"</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>
<span style="color: rgb(0, 0, 0);">}</span></pre>
<pre><span style="font-style: italic; color: rgb(153, 0, 0);">// ElasticMenuBox.as</span>

<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">MenuBox</span>;

<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">MenuBoxMethods</span>;

<span style="font-weight: bold; color: rgb(0, 0, 204);">class</span> factory.<span style="color: rgb(0, 0, 204);">elastic</span>.<span style="color: rgb(0, 0, 204);">ElasticMenuBox</span> <span style="color: rgb(0, 0, 204);">extends</span> MenuBox <span style="color: rgb(0, 0, 204);">implements</span> MenuBoxMethods

<span style="color: rgb(0, 0, 0);">{</span>
 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> ElasticMenuBox<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span>
 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">trace</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 204);">this</span> + <span style="color: rgb(0, 102, 0);">" was created"</span><span style="color: rgb(0, 0, 0);">)</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> display<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : <span style="color: rgb(0, 0, 204);">Void</span>
 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">trace</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 204);">this</span> + <span style="color: rgb(0, 102, 0);">" display()"</span><span style="color: rgb(0, 0, 0);">)</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> <span style="color: rgb(0, 0, 204);">toString</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : <span style="color: rgb(0, 0, 204);">String</span>
 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">return</span> <span style="color: rgb(0, 102, 0);">"ElasticMenuBox"</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

<span style="color: rgb(0, 0, 0);">}</span></pre>
<pre><span style="font-style: italic; color: rgb(153, 0, 0);">// ElasticScrollBar.as</span>

<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">ScrollBar</span>;
<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">ScrollBarMethods</span>;

<span style="font-weight: bold; color: rgb(0, 0, 204);">class</span> factory.<span style="color: rgb(0, 0, 204);">elastic</span>.<span style="color: rgb(0, 0, 204);">ElasticScrollBar</span> <span style="color: rgb(0, 0, 204);">extends</span> ScrollBar <span style="color: rgb(0, 0, 204);">implements</span> ScrollBarMethods
<span style="color: rgb(0, 0, 0);">{</span>
 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> ElasticScrollBar<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span>

 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">trace</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 204);">this</span> + <span style="color: rgb(0, 102, 0);">" was created"</span><span style="color: rgb(0, 0, 0);">)</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> <span style="color: rgb(0, 0, 204);">scroll</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : <span style="color: rgb(0, 0, 204);">Void</span>

 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">trace</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 204);">this</span> + <span style="color: rgb(0, 102, 0);">" scroll()"</span><span style="color: rgb(0, 0, 0);">)</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> <span style="color: rgb(0, 0, 204);">toString</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : <span style="color: rgb(0, 0, 204);">String</span>

 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">return</span> <span style="color: rgb(0, 102, 0);">"ElasticScrollBar"</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>
<span style="color: rgb(0, 0, 0);">}</span></pre>
<pre><span style="font-style: italic; color: rgb(153, 0, 0);">// LiquidContainer.as</span>

<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">Container</span>;

<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">ContainerMethods</span>;

<span style="font-weight: bold; color: rgb(0, 0, 204);">class</span> factory.<span style="color: rgb(0, 0, 204);">liquid</span>.<span style="color: rgb(0, 0, 204);">LiquidContainer</span> <span style="color: rgb(0, 0, 204);">extends</span> Container <span style="color: rgb(0, 0, 204);">implements</span> ContainerMethods

<span style="color: rgb(0, 0, 0);">{</span>
 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> LiquidContainer<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span>
 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">trace</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 204);">this</span> + <span style="color: rgb(0, 102, 0);">" was created"</span><span style="color: rgb(0, 0, 0);">)</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> empty<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : <span style="color: rgb(0, 0, 204);">Void</span>
 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">trace</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 204);">this</span> + <span style="color: rgb(0, 102, 0);">" empty()"</span><span style="color: rgb(0, 0, 0);">)</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> <span style="color: rgb(0, 0, 204);">toString</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : <span style="color: rgb(0, 0, 204);">String</span>
 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">return</span> <span style="color: rgb(0, 102, 0);">"LiquidContainer"</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

<span style="color: rgb(0, 0, 0);">}</span></pre>
<pre><span style="font-style: italic; color: rgb(153, 0, 0);">// LiquidScrollBar.as</span>

<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">ScrollBar</span>;
<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">ScrollBarMethods</span>;

<span style="font-weight: bold; color: rgb(0, 0, 204);">class</span> factory.<span style="color: rgb(0, 0, 204);">liquid</span>.<span style="color: rgb(0, 0, 204);">LiquidScrollBar</span> <span style="color: rgb(0, 0, 204);">extends</span> ScrollBar <span style="color: rgb(0, 0, 204);">implements</span> ScrollBarMethods
<span style="color: rgb(0, 0, 0);">{</span>
 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> LiquidScrollBar<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span>

 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">trace</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 204);">this</span> + <span style="color: rgb(0, 102, 0);">" was created"</span><span style="color: rgb(0, 0, 0);">)</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> <span style="color: rgb(0, 0, 204);">scroll</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : <span style="color: rgb(0, 0, 204);">Void</span>

 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">trace</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 204);">this</span> + <span style="color: rgb(0, 102, 0);">" scroll()"</span><span style="color: rgb(0, 0, 0);">)</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> <span style="color: rgb(0, 0, 204);">toString</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : <span style="color: rgb(0, 0, 204);">String</span>

 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">return</span> <span style="color: rgb(0, 102, 0);">"LiquidScrollBar"</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>
<span style="color: rgb(0, 0, 0);">}</span></pre>
<p>Pour finir, déployons notre système à l’intérieur d’une classe nommée pour l’occasion&nbsp;: <em>UserInterface</em>.</p>
<pre><span style="font-style: italic; color: rgb(153, 0, 0);">// UserInterface.as</span>

<span style="font-style: italic; color: rgb(153, 0, 0);">// On importe la fabrique abstraite</span>
<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">UIsFactory</span>;

<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">ScrollBar</span>;

<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">Container</span>;
<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">MenuBox</span>;

<span style="font-weight: bold; color: rgb(0, 0, 204);">class</span> factory.<span style="color: rgb(0, 0, 204);">UserInterface</span>

<span style="color: rgb(0, 0, 0);">{</span>
 	<span style="color: rgb(0, 0, 204);">private</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">var</span> _oFactory:UIsFactory;

 	<span style="color: rgb(0, 0, 204);">private</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">var</span> _oScrollBar:ScrollBar;
 	<span style="color: rgb(0, 0, 204);">private</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">var</span> _oContainer:Container;
 	<span style="color: rgb(0, 0, 204);">private</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">var</span> _oMenuBox:MenuBox;

 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> myUserInterface<span style="color: rgb(0, 0, 0);">(</span>oFactory:UIsFactory<span style="color: rgb(0, 0, 0);">)</span>

 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="font-style: italic; color: rgb(153, 0, 0);">// on stocke une instance de la fabrique concrÃ¨te spécifiée</span>
  		_oFactory = oFactory;
  		_makeView<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

 	<span style="color: rgb(0, 0, 204);">private</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> _makeView<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : <span style="color: rgb(0, 0, 204);">Void</span>

 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="font-style: italic; color: rgb(153, 0, 0);">// On instancie les objets de la famille choisie (fabrique concrète)</span>
  		_oScrollBar = _oFactory.<span style="color: rgb(0, 0, 204);">createScrollBar</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span>;
  		_oContainer = _oFactory.<span style="color: rgb(0, 0, 204);">createContainer</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span>;
  		_oMenuBox = _oFactory.<span style="color: rgb(0, 0, 204);">createMenuBox</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span>;

  		<span style="font-style: italic; color: rgb(153, 0, 0);">// On utilise le polymorphisme pour manipuler chacun des objets</span>

  		_oScrollBar.<span style="color: rgb(0, 0, 204);">scroll</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span>;
  		_oContainer.<span style="color: rgb(0, 0, 204);">empty</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span>;
  		_oMenuBox.<span style="color: rgb(0, 0, 204);">display</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>
<span style="color: rgb(0, 0, 0);">}</span></pre>
<p>Il ne nous reste plus qu’à lancer l’application en spécifiant la fabrique concrète que l’on veut utiliser, comme ceci&nbsp;:</p>
<pre><span style="font-style: italic; color: rgb(153, 0, 0);">//</span>

<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">UserInterface</span>;
<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">ReboundUIsFactory</span>;
<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">WaterUIsFactory</span>;

<span style="font-style: italic; color: rgb(153, 0, 0);">// J'instancie UserInterface en passant en paramètre une instance</span>
<span style="font-style: italic; color: rgb(153, 0, 0);">// de la fabrique Rebound</span>
<span style="color: rgb(0, 0, 204);">trace</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 102, 0);">"ui1:UserInterface &gt;&gt; using ReboundUIsFactory"</span><span style="color: rgb(0, 0, 0);">)</span>;
<span style="font-weight: bold; color: rgb(0, 0, 204);">var</span> ui1:UserInterface = <span style="font-weight: bold; color: rgb(0, 0, 204);">new</span> UserInterface<span style="color: rgb(0, 0, 0);">(</span> ReboundUIsFactory.<span style="color: rgb(0, 0, 204);">getInstance</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> <span style="color: rgb(0, 0, 0);">)</span>;

<span style="font-style: italic; color: rgb(153, 0, 0);">// Même chose avec une instance de la fabrique Water</span>
<span style="color: rgb(0, 0, 204);">trace</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 102, 0);">"<span style="font-weight: bold; color: rgb(0, 0, 0);">\n</span>"</span> + <span style="color: rgb(0, 102, 0);">"ui2:UserInterface &gt;&gt; using WaterUIsFactory"</span><span style="color: rgb(0, 0, 0);">)</span>;
<span style="font-weight: bold; color: rgb(0, 0, 204);">var</span> ui2:UserInterface = <span style="font-weight: bold; color: rgb(0, 0, 204);">new</span> UserInterface<span style="color: rgb(0, 0, 0);">(</span> WaterUIsFactory.<span style="color: rgb(0, 0, 204);">getInstance</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> <span style="color: rgb(0, 0, 0);">)</span>;</pre>
<p>Voici pour finir une fiche technique résumant les caractéristiques du modèle <strong>Abstract Factory</strong> :</p>
<p><strong>Nom</strong> : Abstract Factory<br />
<strong>Le problème</strong> : Créer une interface pour produire des familles d’objet sans avoir à manipuler directement leurs classes concrètes.<br />
<strong>La solution</strong> : Utiliser une fabrique abstraite en guise<br />
de patron et créer des fabriques concrètes sur ce modèle. Réaliser une<br />
classe abstraite pour chaque type d’objet et créer des classes<br />
concrètes implémentant leurs spécificités au sein de chaque famille.</p>
<p><strong>Les conséquences</strong> :<br />
- On élabore un système qui permet de choisir une famille d’objets parmi plusieurs.<br />
- Ce système est totalement indépendant de la manière dont ses<br />
composants ont été créés, combinés ou sont représentés. Celà facilite<br />
donc la substitution d’une famille par une autre.<br />
- On renforce le couplage au sein d’une famille d’objets afin de les<br />
utiliser par lot. Au résultat, on favorise la cohérence et le maintien<br />
de ceux-ci.</p>
<p>La suite, bientôt&nbsp;!</p>
<p>En attendant n’hésitez pas à me faire partager vos éventuelles questions ou commentaires.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tweenpix.net/2004/04/20/design-patterns-3-abstract-factory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Design Patterns #2 &#8211; Abstract en ActionScript 2.0</title>
		<link>http://blog.tweenpix.net/2004/03/25/design-patterns-2-abstract-en-actionscript-20/</link>
		<comments>http://blog.tweenpix.net/2004/03/25/design-patterns-2-abstract-en-actionscript-20/#comments</comments>
		<pubDate>Thu, 25 Mar 2004 11:36:46 +0000</pubDate>
		<dc:creator>Francis Bourre</dc:creator>
				<category><![CDATA[tech]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[abstract]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[design pattern]]></category>

		<guid isPermaLink="false">http://blog.tweenpix.net/?p=653</guid>
		<description><![CDATA[Avant d&#8217;entamer le chapitre des Design Patterns en AS 2.0 consacré au modèle fabrique abstraite, je vous propose un petit détour qui s&#8217;impose. Il s&#8217;agit d&#8217;une réflexion sur les classes abstraites accompagnéé d&#8217;un pattern que j&#8217;ai développé pour émuler le concept abstract en ActionScript 2.0. Une classe abstraite est une classe sans implémentation, représentée par [...]]]></description>
			<content:encoded><![CDATA[<p>Avant d&#8217;entamer le chapitre des <a href="http://www.tweenpix.net/archives/000277.html" hreflang="fr">Design Patterns en AS 2.0</a> consacré au modèle <em>fabrique abstraite</em>, je vous propose un petit détour qui s&#8217;impose.<br />
Il s&#8217;agit d&#8217;une réflexion sur les classes abstraites accompagnéé d&#8217;un pattern que j&#8217;ai développé pour émuler le concept <em>abstract</em> en ActionScript 2.0.</p>
<p>Une classe abstraite est une classe sans implémentation, représentée par des fonctions virtuelles pures (sans code), dont les implémentations sont différées dans les sous-classes.</p>
<p>Mais à quoi sert une classe abstraite&nbsp;?</p>
<p>Prenons un exemple concret pour commencer, celui d&#8217;un jeu de plateformes. Il pourrait être avantageux de définir une classe abstraite <em>MovingSprite</em> qui contiendrait toutes les propriétés et méthodes récurrentes décrivant les fonctionnalités d&#8217;un objet animé à l&#8217;écran (propriétés&nbsp;: nom, position, taille et méthodes: supprimer, cloner, &#8230; ).<br />
Nous prendrions soin aussi de définir des méthodes abstraites, méthodes qui seraient obligatoirement implémentées par les classes dérivées et qui permettraient à celles-ci d&#8217;exprimer leurs spécificités (bouger, disparaitre, immobiliser &#8230; ).</p>
<p>En résumé, une classe abstraite sert à fournir un modèle générique qui ne sera pas instancié mais juste étendu, une sorte de patron numérique.<br />
L&#8217;implémentation de ses méthodes abstraites par les classes dérivées permettra de faire du polymorphisme d&#8217;héritage. On pourra par exemple passer en revue à l&#8217;intérieur d&#8217;une boucle toutes nos instances des classes dérivées de <em>MovingSprite</em> et invoquer indifféremment sur chacune d&#8217;elles la méthode bouger.</p>
<p>Une classe abstraite doit donc répondre à deux exigences :<br />
- Elle ne peut être instanciée.<br />
- Ses méthodes abstraites doivent être obligatoirement implémentées par les classes dérivées.</p>
<p>Le mot-clef <em>abstract</em> n&#8217;existe pas en ActionScript 2.0. Pour coller au concept, j&#8217;ai donc recours à un subterfuge au niveau design. Pour ce faire, j&#8217;utilise une classe doublée d&#8217;une interface.<br />
Le constructeur de la classe est mis en private pour interdire l&#8217;instanciation et l&#8217;interface contient toutes les méthodes abstraites de la classe.<br />
Une classe concrète voulant hériter d&#8217;une classe abstraite devra donc étendre celle-ci et implémenter l&#8217;interface contenant ses méthodes abstraites.<br />
Dernier point important, la classe devra déclarer (en attributs) toutes les méthodes abstraites afin de permettre le polymorphisme.</p>
<p>Voici un exemple simple illustrant le déploiement de cette architecture&nbsp;:</p>
<pre><span style="color: #0000CC; font-weight: bold;">class</span> shapes.<span style="color: #0000CC;">abstract</span>.<span style="color: #0000CC;">Shape</span>

<span style="color: #000000;">&#123;</span>
 	<span style="color: #0000CC;">private</span> <span style="color: #0000CC; font-weight: bold;">var</span> _nColor:<span style="color: #0000CC;">Number</span>;

 	<span style="color: #990000; font-style: italic;">// On déclare les noms de méthodes abstraites pour permettre le polymorphisme</span>
 	<span style="color: #0000CC;">public</span> <span style="color: #0000CC; font-weight: bold;">var</span> getArea:<span style="color: #0000CC; font-weight: bold;">Function</span>;

 	<span style="color: #990000; font-style: italic;">// Le constructeur est privé pour empêcher l'instanciation</span>

 	<span style="color: #0000CC;">private</span> <span style="color: #0000CC; font-weight: bold;">function</span> Shape<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span>

 	<span style="color: #990000; font-style: italic;">// Méthode non abstraite de la classe</span>
 	<span style="color: #0000CC;">public</span> <span style="color: #0000CC; font-weight: bold;">function</span> setColor<span style="color: #000000;">&#40;</span>nColor:<span style="color: #0000CC;">Number</span><span style="color: #000000;">&#41;</span>

 	<span style="color: #000000;">&#123;</span>
  		_nColor = nColor;
  	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre>
<pre><span style="color: #0000CC;">interface</span> shapes.<span style="color: #0000CC;">abstract</span>.<span style="color: #0000CC;">ShapeMethods</span>
<span style="color: #000000;">&#123;</span>
 	<span style="color: #990000; font-style: italic;">// Liste des méthodes abstraites de la classe Shape.</span>

 	<span style="color: #990000; font-style: italic;">// Toutes les classes concrètes devront implémenter</span>
 	<span style="color: #990000; font-style: italic;">// les méthodes listées.</span>
 	<span style="color: #0000CC;">public</span> <span style="color: #0000CC; font-weight: bold;">function</span> getArea<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> : <span style="color: #0000CC;">Number</span>;

<span style="color: #000000;">&#125;</span></pre>
<pre><span style="color: #990000; font-style: italic;">// import des deux classes pour émuler le concept abstract</span>
<span style="color: #0000CC;">import</span> shapes.<span style="color: #0000CC;">abstract</span>.<span style="color: #0000CC;">Shape</span>;
<span style="color: #0000CC;">import</span> shapes.<span style="color: #0000CC;">abstract</span>.<span style="color: #0000CC;">ShapeMethods</span>;

&nbsp;
<span style="color: #990000; font-style: italic;">// Rectangle hérite de Shape et doit implémenter ses méthodes</span>
<span style="color: #990000; font-style: italic;">// en respectant le typage.</span>
<span style="color: #0000CC; font-weight: bold;">class</span> shapes.<span style="color: #0000CC;">Square</span> <span style="color: #0000CC;">extends</span> Shape <span style="color: #0000CC;">implements</span> ShapeMethods

<span style="color: #000000;">&#123;</span>
 	<span style="color: #0000CC;">private</span> <span style="color: #0000CC; font-weight: bold;">var</span> _nSide:<span style="color: #0000CC;">Number</span>;

 	<span style="color: #0000CC;">public</span> <span style="color: #0000CC; font-weight: bold;">function</span> Square<span style="color: #000000;">&#40;</span>nSide:<span style="color: #0000CC;">Number</span><span style="color: #000000;">&#41;</span>
 	<span style="color: #000000;">&#123;</span>

  		_nSide = nSide;
  	<span style="color: #000000;">&#125;</span>

 	<span style="color: #990000; font-style: italic;">// La méthode abstraite getArea est implémentée comme spécifié dans l'interface</span>
 	<span style="color: #0000CC;">public</span> <span style="color: #0000CC; font-weight: bold;">function</span> getArea<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> : <span style="color: #0000CC;">Number</span>
 	<span style="color: #000000;">&#123;</span>

  		<span style="color: #0000CC;">return</span> _nSide * _nSide;
  	<span style="color: #000000;">&#125;</span>

 	<span style="color: #0000CC;">public</span> <span style="color: #0000CC; font-weight: bold;">function</span> <span style="color: #0000CC;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> : <span style="color: #0000CC;">String</span> <span style="color: #000000;">&#123;</span> <span style="color: #0000CC;">return</span> <span style="color: #006600;">"Square"</span>; <span style="color: #000000;">&#125;</span>

<span style="color: #000000;">&#125;</span></pre>
<pre><span style="color: #990000; font-style: italic;">// import des deux classes pour émuler le concept abstract</span>
<span style="color: #0000CC;">import</span> shapes.<span style="color: #0000CC;">abstract</span>.<span style="color: #0000CC;">Shape</span>;
<span style="color: #0000CC;">import</span> shapes.<span style="color: #0000CC;">abstract</span>.<span style="color: #0000CC;">ShapeMethods</span>;

&nbsp;
<span style="color: #990000; font-style: italic;">// Circle hérite de Shape et doit implémenter ses méthodes</span>
<span style="color: #990000; font-style: italic;">// en respectant le typage.</span>
<span style="color: #0000CC; font-weight: bold;">class</span> shapes.<span style="color: #0000CC;">Circle</span> <span style="color: #0000CC;">extends</span> Shape <span style="color: #0000CC;">implements</span> ShapeMethods

<span style="color: #000000;">&#123;</span>
 	<span style="color: #0000CC;">private</span> <span style="color: #0000CC; font-weight: bold;">var</span> _nRadius:<span style="color: #0000CC;">Number</span>;

 	<span style="color: #0000CC;">public</span> <span style="color: #0000CC; font-weight: bold;">function</span> Circle<span style="color: #000000;">&#40;</span>nRadius:<span style="color: #0000CC;">Number</span><span style="color: #000000;">&#41;</span>
 	<span style="color: #000000;">&#123;</span>

  		_nRadius = nRadius;
  	<span style="color: #000000;">&#125;</span>

 	<span style="color: #990000; font-style: italic;">// La méthode abstraite getArea est implémentée comme spécifié dans l'interface</span>
 	<span style="color: #0000CC;">public</span> <span style="color: #0000CC; font-weight: bold;">function</span> getArea<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> : <span style="color: #0000CC;">Number</span>
 	<span style="color: #000000;">&#123;</span>

  		<span style="color: #0000CC;">return</span> <span style="color: #000000;">2</span> * _nRadius * <span style="color: #0000CC;">Math</span>.<span style="color: #0000CC;">PI</span>;
  	<span style="color: #000000;">&#125;</span>

 	<span style="color: #0000CC;">public</span> <span style="color: #0000CC; font-weight: bold;">function</span> <span style="color: #0000CC;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> : <span style="color: #0000CC;">String</span> <span style="color: #000000;">&#123;</span> <span style="color: #0000CC;">return</span> <span style="color: #006600;">"Circle"</span>; <span style="color: #000000;">&#125;</span>

<span style="color: #000000;">&#125;</span></pre>
<pre><span style="color: #990000; font-style: italic;">// import des deux classes pour émuler le concept abstract</span>
<span style="color: #0000CC;">import</span> shapes.<span style="color: #0000CC;">abstract</span>.<span style="color: #0000CC;">Shape</span>;
<span style="color: #0000CC;">import</span> shapes.<span style="color: #0000CC;">abstract</span>.<span style="color: #0000CC;">ShapeMethods</span>;

&nbsp;
<span style="color: #990000; font-style: italic;">// Rectangle hérite de Shape et doit implémenter ses méthodes</span>
<span style="color: #990000; font-style: italic;">// en respectant le typage.</span>
<span style="color: #0000CC; font-weight: bold;">class</span> shapes.<span style="color: #0000CC;">Rectangle</span> <span style="color: #0000CC;">extends</span> Shape <span style="color: #0000CC;">implements</span> ShapeMethods

<span style="color: #000000;">&#123;</span>
 	<span style="color: #0000CC;">private</span> <span style="color: #0000CC; font-weight: bold;">var</span> _nWidth:<span style="color: #0000CC;">Number</span>, _nHeight:<span style="color: #0000CC;">Number</span>;

 	<span style="color: #0000CC;">public</span> <span style="color: #0000CC; font-weight: bold;">function</span> Rectangle<span style="color: #000000;">&#40;</span>nWidth:<span style="color: #0000CC;">Number</span>, nHeight:<span style="color: #0000CC;">Number</span><span style="color: #000000;">&#41;</span>
 	<span style="color: #000000;">&#123;</span>

  		_nWidth = nWidth;
  		_nHeight = nHeight;
  	<span style="color: #000000;">&#125;</span>

 	<span style="color: #990000; font-style: italic;">// La méthode abstraite getArea est implémentée comme spécifié dans l'interface</span>
 	<span style="color: #0000CC;">public</span> <span style="color: #0000CC; font-weight: bold;">function</span> getArea<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> : <span style="color: #0000CC;">Number</span>
 	<span style="color: #000000;">&#123;</span>

  		<span style="color: #0000CC;">return</span> _nWidth * _nHeight;
  	<span style="color: #000000;">&#125;</span>

 	<span style="color: #0000CC;">public</span> <span style="color: #0000CC; font-weight: bold;">function</span> <span style="color: #0000CC;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> : <span style="color: #0000CC;">String</span> <span style="color: #000000;">&#123;</span> <span style="color: #0000CC;">return</span> <span style="color: #006600;">"Rectangle"</span>; <span style="color: #000000;">&#125;</span>

<span style="color: #000000;">&#125;</span></pre>
<pre><span style="color: #990000; font-style: italic;">// On importe la classe abstraite</span>
<span style="color: #0000CC;">import</span> shapes.<span style="color: #0000CC;">abstract</span>.<span style="color: #0000CC;">Shape</span>;
&nbsp;
<span style="color: #0000CC; font-weight: bold;">class</span> shapes.<span style="color: #0000CC;">ShapesManager</span>

<span style="color: #000000;">&#123;</span>
 	<span style="color: #990000; font-style: italic;">// container pour stocker les objets</span>
 	<span style="color: #0000CC;">private</span> <span style="color: #0000CC;">static</span> <span style="color: #0000CC; font-weight: bold;">var</span> _aShapes:<span style="color: #0000CC;">Array</span> = <span style="color: #0000CC; font-weight: bold;">new</span> <span style="color: #0000CC;">Array</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;

 	<span style="color: #990000; font-style: italic;">// Surface totale des objets agrégés dans le manager</span>

 	<span style="color: #0000CC;">public</span> <span style="color: #0000CC;">static</span> <span style="color: #0000CC; font-weight: bold;">var</span> totalArea:<span style="color: #0000CC;">Number</span> = <span style="color: #000000;">0</span>;

 	<span style="color: #990000; font-style: italic;">// Méthode pour ajouter un objet au manager</span>
 	<span style="color: #990000; font-style: italic;">// On s'assure grâce au typage fort qu'il s'agit bien d'un objet Shape</span>

 	<span style="color: #0000CC;">public</span> <span style="color: #0000CC;">static</span> <span style="color: #0000CC; font-weight: bold;">function</span> addShape<span style="color: #000000;">&#40;</span>s:Shape<span style="color: #000000;">&#41;</span>
 	<span style="color: #000000;">&#123;</span>
  		<span style="color: #990000; font-style: italic;">// On ajoute l'objet au tableau</span>
  		_aShapes.<span style="color: #0000CC;">push</span><span style="color: #000000;">&#40;</span>s<span style="color: #000000;">&#41;</span>;
  		<span style="color: #990000; font-style: italic;">// On peut faire du polymorphisme</span>

  		totalArea += s.<span style="color: #0000CC;">getArea</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
  	<span style="color: #000000;">&#125;</span>

 	<span style="color: #990000; font-style: italic;">// Méthode pour supprimer un objet du manager en fournissant son id</span>

 	<span style="color: #0000CC;">public</span> <span style="color: #0000CC;">static</span> <span style="color: #0000CC; font-weight: bold;">function</span> removeShape<span style="color: #000000;">&#40;</span>nID:<span style="color: #0000CC;">Number</span><span style="color: #000000;">&#41;</span> : <span style="color: #0000CC;">Void</span>

 	<span style="color: #000000;">&#123;</span>
  		<span style="color: #990000; font-style: italic;">// On vérifie que l'ID est bien valide</span>
  		<span style="color: #0000CC;">if</span> <span style="color: #000000;">&#40;</span>nID&gt;=_aShapes.<span style="color: #0000CC;">length</span> || nID &lt; <span style="color: #000000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #0000CC;">throw</span> <span style="color: #0000CC; font-weight: bold;">new</span> <span style="color: #0000CC;">Error</span><span style="color: #000000;">&#40;</span><span style="color: #006600;">"error, wrong ID !"</span><span style="color: #000000;">&#41;</span>;

  		<span style="color: #990000; font-style: italic;">// On réactualise la valeur de la surface totale</span>

  		totalArea -= _aShapes<span style="color: #000000;">&#91;</span>nID<span style="color: #000000;">&#93;</span>.<span style="color: #0000CC;">getArea</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;

  		<span style="color: #990000; font-style: italic;">// On supprime l'objet</span>
  		<span style="color: #0000CC;">delete</span> _aShapes<span style="color: #000000;">&#91;</span>nID<span style="color: #000000;">&#93;</span>;
  	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre>
<pre><span style="color: #990000; font-style: italic;">// test.fla</span>
&nbsp;
<span style="color: #990000; font-style: italic;">// Import du package</span>
<span style="color: #0000CC;">import</span> shapes.*
&nbsp;
<span style="color: #990000; font-style: italic;">// Ajout des formes</span>
ShapesManager.<span style="color: #0000CC;">addShape</span><span style="color: #000000;">&#40;</span> <span style="color: #0000CC; font-weight: bold;">new</span> Rectangle<span style="color: #000000;">&#40;</span><span style="color: #000000;">5</span>, <span style="color: #000000;">10</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>;
ShapesManager.<span style="color: #0000CC;">addShape</span><span style="color: #000000;">&#40;</span> <span style="color: #0000CC; font-weight: bold;">new</span> Square<span style="color: #000000;">&#40;</span><span style="color: #000000;">5</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>;
ShapesManager.<span style="color: #0000CC;">addShape</span><span style="color: #000000;">&#40;</span> <span style="color: #0000CC; font-weight: bold;">new</span> Circle<span style="color: #000000;">&#40;</span><span style="color: #000000;">6</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>;

&nbsp;
<span style="color: #990000; font-style: italic;">// Sortie de la surface totale</span>
<span style="color: #0000CC;">trace</span><span style="color: #000000;">&#40;</span> ShapesManager.<span style="color: #0000CC;">totalArea</span> <span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #990000; font-style: italic;">// Suppression du rectangle</span>
ShapesManager.<span style="color: #0000CC;">removeShape</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">2</span><span style="color: #000000;">&#41;</span>;
&nbsp;

<span style="color: #990000; font-style: italic;">// Sortie de la surface totale</span>
<span style="color: #0000CC;">trace</span><span style="color: #000000;">&#40;</span> ShapesManager.<span style="color: #0000CC;">totalArea</span> <span style="color: #000000;">&#41;</span>;</pre>
<p>La suite ce week-end avec le modèle <em>fabrique abstraite</em>.</p>
<p>En attendant n&#8217;hésitez pas à me faire partager vos éventuelles questions ou commentaires.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tweenpix.net/2004/03/25/design-patterns-2-abstract-en-actionscript-20/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Design Patterns #1 &#8211; Singleton</title>
		<link>http://blog.tweenpix.net/2004/02/21/design-patterns-1-singleton/</link>
		<comments>http://blog.tweenpix.net/2004/02/21/design-patterns-1-singleton/#comments</comments>
		<pubDate>Sat, 21 Feb 2004 21:03:51 +0000</pubDate>
		<dc:creator>Francis Bourre</dc:creator>
				<category><![CDATA[tech]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[design pattern]]></category>
		<category><![CDATA[singleton]]></category>

		<guid isPermaLink="false">http://blog.tweenpix.net/?p=447</guid>
		<description><![CDATA[Deux mois se sont écoulés depuis la publication de la pseudo préface de ce dossier ambitieux sur les design patterns en ActionScript 2.0. Voici enfin aujourd&#8217;hui la première partie, chargée d&#8217;introduire les modèles de création et d&#8217;exposer au grand jour le pattern Singleton. Une petite mise en garde de rigueur avant de commencer : Pour [...]]]></description>
			<content:encoded><![CDATA[<p>Deux mois se sont écoulés depuis la publication de la pseudo <a href="http://blog.tweenpix.net/2003/12/21/design-patterns-introduction/">préface</a> de ce dossier ambitieux sur les design patterns en ActionScript 2.0.</p>
<p>Voici enfin aujourd&#8217;hui la première partie, chargée d&#8217;introduire les modèles de création et d&#8217;exposer au grand jour le pattern Singleton.</p>
<p>Une petite mise en garde de rigueur avant de commencer :</p>
<p>Pour aborder cette série d&#8217;articles, il est indispensable que vous possédiez déjà des connaissances de base en programmation orientée objet.</p>
<p>Maîtriser la <a href="http://www.tweenpix.net/articles/as2p2">syntaxe ActionScript 2.0</a> sera biensûr un atout majeur qui vous permettra de décortiquer les exemples donnés tout au long des différents dossiers.</p>
<p>En dernier préambule, j&#8217;aimerai insister aussi sur le fait que la plupart des patterns prennent vraiment tout leur sens lorsqu&#8217;ils sont employés à l&#8217;intérieur de véritables applications ou plutôt &#8230; Laissez moi reformuler ma phrase : L&#8217;intérêt de chaque pattern devient évident et limpide lorque l&#8217;on s&#8217;est déjà heurté au problème dont il se propose d&#8217;être le remède. Pour résumer, c&#8217;est quand on commence à se confronter aux réelles difficultés liées au développement que ces élégantes abstractions deviennent limpides. Il est en effet souvent très difficile (voir impossible) de cultiver la robustesse, la sécurité, la durabilité ou l&#8217;évolutivité du code sans recourir à toutes ces bottes secrètes. Cet apprentissage (comme la plupart) peut biensûr se dérouler de façon totalement intuitive tout au long des expériences de chacun. Passer par la théorie c&#8217;est se donner des chances supplémentaires de voir clair vite et bien.</p>
<p>En général un modèle de conception se décompose en quatre parties :</p>
<p>- Le nom</p>
<p>- Le problème</p>
<p>- La solution</p>
<p>- Les conséquences</p>
<p>Ces caractéristiques portent des noms assez explicites pour m&#8217;éviter la rédaction inutile d&#8217;un glossaire pompeux et redondant. Si tel n&#8217;était pas le cas, je reste persuadé que les explications qui suivront vous aideront à mettre en lumière leur vocation respective.</p>
<p>La première famille de modèles que nous allons donc aborder est spécialisée dans la création, comprenez par là : Processus d&#8217;instanciation.</p>
<p>Il s&#8217;agit des <strong>modèles créateurs</strong>.</p>
<p>L&#8217;intérêt majeur de cette famille, c&#8217;est de privilégier l&#8217;abstraction d&#8217;un processus de création plutôt que de coder celui-ci en dur et se heurter par là même (tôt ou tard) à une inertie écrasante du système, que je qualifierai (avec humour) de <em>fossilisation</em> irréversible de l&#8217;application.</p>
<p>Pour prendre une image du monde réel (encore une), il est plus facile en tant que patron d&#8217;un hôtel d&#8217;employer un cuisinier pour répondre à l&#8217;attente de ses clients concernant leur appétit et goûts respectifs, plutôt que de laisser la possibilité à chacun de se restaurer en mettant à disposition locaux, ustensiles recettes et provisions de l&#8217;établissement. Il n&#8217;est pas besoin d&#8217;être un savant informaticien pour cerner les problèmes de logistique engendrés par la deuxième solution.</p>
<p>Offrir la reponsabilité à une entité de s&#8217;occuper de la création de chaque plat en s&#8217;adaptant à la demande de notre aimable clientèle ainsi qu&#8217;aux contraintes imposées par le système (stock, coûts &#8230;) nous permet non seulement d&#8217;occulter la fabrication des plats mais aussi d&#8217;interchanger le détenteur de cette responsabilité selon nos besoins ou exigences (grand chef cusinier pour les soirées V.I.P contre équipe d&#8217;apprentis pour les grands rushs de midi).</p>
<p>Pour résumer, le principe fédérateur de cette famille de patterns, c&#8217;est d&#8217;encapsuler la connaissance des classes concrètes (recette de chaque plat) que le système (hôtel) utilise et masquer le déroulement et le paramétrage d&#8217;une instanciation (fabrication d&#8217;un plat).</p>
<p>Pour commencer, voici la liste des patterns appartenant à cette famille de modèles (modèles créateurs) :</p>
<p>- Fabrique abstraite</p>
<p>- Monteur</p>
<p>- Fabrication</p>
<p>- Prototype</p>
<p>- Singleton</p>
<p>Nous allons commencer cette étude par un patterns très utilisé, j&#8217;ai nommé le <strong>Singleton</strong>.</p>
<p>Il est souvent important au sein d&#8217;une application de pouvoir s&#8217;assurer premièrement de l&#8217;unicité d&#8217;un objet, deuxièmement de son accessibilité à tout moment par les autres objets de l&#8217;application sans avoir recours à des références multiples.</p>
<p>Comme un exemple est souvent beaucoup plus parlant qu&#8217;une longue explication technnique, nous allons illustrer l&#8217;utilisation de ce pattern en nous appuyant sur une situation concréte. Pour les besoins de cette démonstration nous allons créer une classe abstraite <em>Connection</em> dont le rôle sera de créer une connexion socket entre le client Flash et un serveur unique prédéfini.</p>
<p>Vous conviendrez au vu de l&#8217;énoncé qu&#8217;il serait maladroit voir catastrophique d&#8217;avoir des instances multiples de <em>Connection</em>.</p>
<p>En utilisant le pattern Singleton sur notre classe <em>Connection</em> nous garantissons le fait qu&#8217;il ne peut y avoir qu&#8217;une seule instance de connexion dans notre application.</p>
<p>Cerise sur le gâteau ce pattern fournira un point d&#8217;accès unique et global à tous les éléments de notre application nécessitant les services de celle-ci.</p>
<pre lang="actionscript">
// Classe fictive pour illustrer le déploiement du pattern Singleton

class Connection
{
 	// Membre statique protected (faute de pouvoir être placé en privé)
 	// servant à stocker une référence de notre connection, .
 	private static var _oInstance:Connection;

 	// Le constructeur est placé en protected.
 	// Ceci garantit déjà l'impossibilité d'instancier directement une connection
 	// sans passer par le point d'accès.
     private function Connection()
 	{
  		trace("Constructeur appelé");
  	}

 	// L'unique point d'accès qui empêche toute duplication.
     public static function get instance() : Connection
     {
  		// Pour créer une connection (instance de Connection)
  		// On s'assure que celle-ci n'existe pas déjà.
  		if (_oInstance == undefined) _oInstance = new Connection();
  		// Dans tous les cas, on retourne une référence vers l'objet
  		// à celui qui en a fait la demande.
  		return _oInstance;
      }

 	// On prévoit une méthode pour détruire notre instance
 	// en cas de besoin de réinitialisation
 	// ou de libération de la mémoire.
 	public static function release() : Void
 	{
  		// Si l'instance existe on la détruit.
  		if (_oInstance)
  		{
   			trace("instance détruite");
   			delete _oInstance;
   		}
  	}

 	// Maintenant que le pattern est déployé voici le coeur
 	// de notre objet exposé avec ses différentes méthodes :
 	public function connect() : Void {}
 	public function disconnect() : Void {}
}
</pre>
<p>Note : Le fait que le player Flash ne gére pas le muti-threading nous protège des soucis d&#8217;initialisation différée comme dans certains langages comme C++.</p>
<p>La question légitime que l&#8217;on est maintenant en droit de se poser face au modéle Singleton c&#8217;est pourquoi ne pas passer en statique toutes les méthodes comme je le fais avec la <a href="http://blog.tweenpix.net/2004/02/18/soundfactory/">SoundFactory</a> ?</p>
<p>Les deux seuls avantages en ActionScript à retirer sont :</p>
<p>- D&#8217;avoir plusieurs instances d&#8217;une classe mère par extensions multiples. &#8211; D&#8217;avoir la possibilité en cours de développement de modifier le design parceque l&#8217;on s&#8217;aperçoit que l&#8217;on nécessite finalement plusieurs instances de la même classe.</p>
<p>Voici pour finir une fiche technnique pour résumer les caractéristiques du modèle Singleton :</p>
<p>Nom : <strong>Singleton</strong></p>
<p>Le problème : S&#8217;assurer de l&#8217;unicité de l&#8217;instance d&#8217;une classe</p>
<p>La solution :</p>
<p>- Définir un membre privé static pour stocker l&#8217;instance.</p>
<p>- Définir une méthode publique pour accéder à celle-ci.</p>
<p>- Mettre le constructeur en protected (private en AS 2.0).</p>
<p>Les conséquences :</p>
<p>- Contrôle d&#8217;accès à l&#8217;instance régulé.</p>
<p>- Changement de stratégie possible à tout moment.</p>
<p>Et pour accompagner ce résumé voici une implémentation générique du pattern Singleton en ActionScript 2.0 : </p>
<pre lang="actionscript">
class Singleton
{
 	private static var _oInstance:Singleton;

     private function Singleton() {}

     public static function getInstance() : Singleton
     {
  		if (_oInstance == undefined) _oInstance = new Singleton();
  		return _oInstance;
      }

 	public static function release() : Void
 	{
  		if (_oInstance) delete _oInstance;
  	}
}
</pre>
<p>Le prochain article traitera du modèle <em>fabrique abstraite</em>. En attendant n&#8217;hésitez pas à me faire partager vos éventuelles questions ou commentaires.</p>
<p>Les fichiers source sont disponibles <a href="http://www.tweenpix.net/files/Singleton.zip">ici</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tweenpix.net/2004/02/21/design-patterns-1-singleton/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
		<item>
		<title>design patterns &#8211; introduction</title>
		<link>http://blog.tweenpix.net/2003/12/21/design-patterns-introduction/</link>
		<comments>http://blog.tweenpix.net/2003/12/21/design-patterns-introduction/#comments</comments>
		<pubDate>Sun, 21 Dec 2003 17:49:15 +0000</pubDate>
		<dc:creator>Francis Bourre</dc:creator>
				<category><![CDATA[tech]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[design pattern]]></category>

		<guid isPermaLink="false">http://blog.tweenpix.net/?p=426</guid>
		<description><![CDATA[&#8230; Bande-annonce &#8230; Dans les mois qui viennent je vous propose de vous faire partager mes expérimentations concernant l&#8217;implémentation des design patterns en ActionScript2.0. &#8230; Générique &#8230; Mais commençons par le commencement, les design patterns c&#8217;est quoi ? Les modèles de conception sont des solutions simples et élégantes à des problèmes spécifiques de conception de [...]]]></description>
			<content:encoded><![CDATA[<p>&#8230; Bande-annonce &#8230;</p>
<p>Dans les mois qui viennent je vous propose de vous faire partager mes expérimentations concernant l&#8217;implémentation des design patterns en ActionScript2.0.</p>
<p>&#8230; Générique &#8230;</p>
<p>Mais commençons par le commencement, les design patterns c&#8217;est quoi ?</p>
<p>Les modèles de conception sont des solutions simples et élégantes à des problèmes spécifiques de conception de logiciels orientés-objet. (Design patterns &#8211; GOF)</p>
<p>Il s&#8217;agit donc en résumé, de décrire un fonctionnement et le rendre générique pour qu&#8217;il soit toujours réutilisable dans les mêmes circonstances.</p>
<p>J&#8217;imagine que cela ne doit pas être très limpide pour tous ceux qui n&#8217;ont jamais eu l&#8217;occasion d&#8217;aborder le sujet. Je vais donc tenter d&#8217;illustrer et vulgariser cette définition un peu solennelle en vous offrant une jolie métaphore (un peu tirée par les cheveux certes) en guise d&#8217;exemple.</p>
<p>Je suis réalisateur d&#8217;une émission de télévision dont le thème principal est l&#8217;Europe. Si si c&#8217;est vrai, je vous assure ! Chaque semaine, je reçois deux invités venant des quatre coins du continent. Problème récurrent : Mes deux invités ne parlent pas la même langue, difficile donc de les faire s&#8217;entretenir sur un sujet donné une heure durant. Pour éviter que mon talk-show ressemble à une tour de Babel cathodique, je vais pour l&#8217;occasion recourir à un design pattern éprouvé par tous les médias internationaux. C&#8217;est un pote responsable de l&#8217;information sur CNN qui me l&#8217;a conseillé. Il s&#8217;agit du modéle : Traduction simultanée. Solution : Embaucher un interpréte qui s&#8217;occupera en temps réel de réaliser les traductions qui seront retransmises à chaque intervenant par le biais d&#8217;une oreillette. Avouez que c&#8217;est super ingénieux !</p>
<p><img src='http://blog.tweenpix.net/wp-content/gallery/general/ryan_white.jpg' alt='ryan_white.jpg' class='ngg-singlepic ngg-none' /></p>
<p>Chaque fois donc, qu&#8217;une émission veut permettre à deux invités de nationalités différentes de communiquer sans difficulté, elle va recourir au design pattern Traduction simultanée. Il s&#8217;agit d&#8217;un modéle qui a fait ses preuves au fil des ans et permet ainsi de gagner du temps et de l&#8217;énergie dans la réalisation des programmes TV du monde entier.</p>
<p>En grossissant le trait, un design pattern est donc ( comme l&#8217;illustre l&#8217;exemple ci-dessus ) une solution standard permettant à un réalisateur TV (ou un développeur orienté objet ) de se sortir d&#8217;affaires dans un cas donné (souvent assez spécifique) sans qu&#8217;il ait à avoir à réinventer la roue à chaque représentation de celui-ci.</p>
<p>Pour utiliser quelques synonymes évocateurs faits maison et enfoncer le clou, je qualifierai un modéle de conception de : Recette miracle, moule conceptuel, empreinte ou même carte aux trésors permettant d&#8217;arriver à ses fins à chaque répétition d&#8217;une situtation spécifique.</p>
<p>Fin de l&#8217;épisode pilote, la prochaine fois je démarrerai la première saison (première famille de modèles) en traitant des modèles créateurs. Le suspens est à son comble ! ^^</p>
<p>&#8230; Générique &#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tweenpix.net/2003/12/21/design-patterns-introduction/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>isométrie et z-sorting</title>
		<link>http://blog.tweenpix.net/2003/10/11/isometrie-et-z-sorting/</link>
		<comments>http://blog.tweenpix.net/2003/10/11/isometrie-et-z-sorting/#comments</comments>
		<pubDate>Sat, 11 Oct 2003 07:06:12 +0000</pubDate>
		<dc:creator>Francis Bourre</dc:creator>
				<category><![CDATA[tech]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[work]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[isometric]]></category>
		<category><![CDATA[z-sorting]]></category>

		<guid isPermaLink="false">http://blog.tweenpix.net/?p=394</guid>
		<description><![CDATA[En m&#8217;intéressant de près à l&#8217;isométrie, je me suis aperçu que les méthodes pronées par Jobe Makar (Flash MX Games Design Demystified) et consorts au sujet du z-sorting n&#8217;étaient pas du tout adaptées pour un moteur 3D isométrique dont l&#8217;objectif final serait d&#8217;afficher des animations. Je vous propose de partager aujourd&#8217;hui la solution que j&#8217;utilise. [...]]]></description>
			<content:encoded><![CDATA[<p>En m&#8217;intéressant de près à l&#8217;isométrie, je me suis aperçu que les méthodes pronées par Jobe Makar <a href="http://www.amazon.com/exec/obidos/tg/detail/-/0201770210/103-0421988-5159053?v=glance" hreflang="uk">(Flash MX Games Design Demystified)</a> et consorts au sujet du z-sorting n&#8217;étaient pas du tout adaptées pour un moteur 3D isométrique dont l&#8217;objectif final serait d&#8217;afficher des animations.</p>
<p>Je vous propose de partager aujourd&#8217;hui la solution que j&#8217;utilise. Elle vous permettra de gérer les profondeurs sans bug d&#8217;affichage dans un moteur 3d isométrique animé.</p>
<p>Le concept récurrent pour gérer la profondeur d&#8217;un objet dans un tileworld isométrique est d&#8217;assigner un z-sorting incrémenté de gauche à droite sur l&#8217;axe des x, puis de bas en haut sur l&#8217;axe des y comme indiqué sur le schéma ci-dessous&nbsp;:</p>
<p><img src="http://www.tweenpix.net/img/zsshots/zs0.gif" alt="" /></p>
<p>Ce système fonctionne à merveille tant que l&#8217;on se contente du fait que chaque objet se trouvant à une position (x,y) se déplacera sur une case voisine d&#8217;un seul jet, sans interpolation de mouvement, autrement dit sans se trouver à un instant t à cheval entre deux cases.<br />
Pourquoi me direz vous&nbsp;?</p>
<p>Considérons l&#8217;exemple ci-dessous&nbsp;:</p>
<p><img src="http://www.tweenpix.net/img/zsshots/zs1.gif" alt="" /></p>
<p>Un personnage se trouvant à la position 1,1 et voulant se rendre à la position 1,0 va devoir choisir son camp. S&#8217;il garde 4 comme profondeur le temps de l&#8217;animation pour se rendre sur la case destination, il va passer devant l&#8217;objet qui se trouve en 2,0.</p>
<p>S&#8217;il choisit de prendre directement sa profondeur d&#8217;arrivée (1), il sera le temps de son trajet affiché derrière l&#8217;objet se trouvant en 2,0.</p>
<p><img src="http://www.tweenpix.net/img/zsshots/zs2.gif" alt="" /></p>
<p>On est confronté au même probléme dans le sens inverse comme vous pouvez le remarquer&nbsp;:</p>
<p><img src="http://www.tweenpix.net/img/zsshots/zs3.gif" alt="" /></p>
<p>La plupart des moteurs utilisant ce système réussissent à tricher en jouant sur la taille des objets à l&#8217;intérieur des cases et sur l&#8217;instant ou la valeur z-sorting de l&#8217;objet en mouvement est modifiée. Mais ces solutions au bout du compte ne sont vraiment pas satisfaisantes pour gérer l&#8217;affichage de façon propre et logique.</p>
<p>D&#8217;où l&#8217;idée d&#8217;opter pour une organisation comme celle-ci, avec un z-sorting incrémenté en diagonales&nbsp;:</p>
<p><img src="http://www.tweenpix.net/img/zsshots/zs5.gif" alt="" /></p>
<p>Cette fois-ci les animations sur l&#8217;axe des y peuvent-être gérées sans bug d&#8217;affichage&nbsp;:</p>
<p><img src="http://www.tweenpix.net/img/zsshots/zs4.gif" alt="" /></p>
<p>Mais les esprits judicieux auront remarqué que le probléme est maintenant répercuté sur l&#8217;axe des x&nbsp;:</p>
<p><img src="http://www.tweenpix.net/img/zsshots/zs6.gif" alt="" /></p>
<p>Sans plus attendre, voici la solution finale, le même tableau mais avec des intervalles en dizaine&nbsp;:</p>
<p><img src="http://www.tweenpix.net/img/zsshots/zs7.gif" alt="" /></p>
<p>Hum &#8230; Quoi de mieux me direz-vous&nbsp;?<br />
L&#8217;idée est d&#8217;incrémenter de 15 la profondeur d&#8217;un personnage voulant se déplacer vers la droite sur l&#8217;axe des x (50 dans l&#8217;exemple devient 65) et de lui donner à la fin de son parcours la profondeur de la case d&#8217;arrivée (80 dans l&#8217;exemple ci-dessous)&nbsp;:</p>
<p><img src="http://www.tweenpix.net/img/zsshots/zs8.gif" alt="" /></p>
<p>Même chose dans l&#8217;autre sens, on enléve 15 à la profondeur d&#8217;un personnage voulant se déplacer vers la gauche sur l&#8217;axe des x (50 devenant 35 dans le cas précis) et on lui attribue à la fin de son trajet la profondeur de la case destination (il passe donc de 35 à 20 en profondeur une fois arrivé)&nbsp;:</p>
<p><img src="http://www.tweenpix.net/img/zsshots/zs9.gif" alt="" /></p>
<p>Dernier point, quelle méthode utiliser pour calculer la profondeur d&#8217;un objet en connaissant la largeur et la hauteur de la grille ainsi que sa position x et y&nbsp;?<br />
C&#8217;était le sujet d&#8217;un précédent thread, et je remercie Didier d&#8217;avoir trouvé une solution très élégante et rapide pour gérer cette problématique.<br />
Voici le code que j&#8217;utilise&nbsp;:</p>
<pre> <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> _sum<span style="color: #66cc66;">&#40;</span>n:<span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">Number</span> <span style="color: #66cc66;">&#123;</span>

         <span style="color: #b1b100;">return</span> <span style="color: #66cc66;">&#40;</span>n * <span style="color: #66cc66;">&#40;</span>n + <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> / <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
   <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> calculDepth<span style="color: #66cc66;">&#40;</span>x:<span style="color: #0066CC;">Number</span>, y:<span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>

         <span style="color: #000000; font-weight: bold;">var</span> r:<span style="color: #0066CC;">Number</span> = _sum<span style="color: #66cc66;">&#40;</span>x + y<span style="color: #66cc66;">&#41;</span> + x + <span style="color: #cc66cc;">1</span>;
         r = <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>x + y<span style="color: #66cc66;">&#41;</span> &gt; <span style="color: #66cc66;">&#40;</span>grid.<span style="color: #006600;">x</span>-<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> ? r -= _sum<span style="color: #66cc66;">&#40;</span>x + y - <span style="color: #66cc66;">&#40;</span>grid.<span style="color: #006600;">x</span>-<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> : r;
         r = <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>x + y<span style="color: #66cc66;">&#41;</span> &gt; grid.<span style="color: #006600;">y</span><span style="color: #66cc66;">&#41;</span> ? r -= _sum<span style="color: #66cc66;">&#40;</span>x + y - grid.<span style="color: #006600;">y</span><span style="color: #66cc66;">&#41;</span> : r;
         <span style="color: #b1b100;">return</span> <span style="color: #66cc66;">&#40;</span>r*<span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span></pre>
<p>Voila, j&#8217;espère que le concept que j&#8217;ai développé et utilise couramment pourra contribuer à remplir un peu le vide auquel je me suis confronté lors de mes investigations sur le sujet.</p>
<p>Je tiens à remercier tout particulièrement Joan pour ses idées et Didier pour son algorithme de calcul remarquable ainsi que Jean-Louis pour la conversion en AS.<br />
Comme d&#8217;habitude, vos questions, commentaires ou critiques sont les bienvenue.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tweenpix.net/2003/10/11/isometrie-et-z-sorting/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

