<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet title="XSL formatting" type="text/xsl" href="http://www.ekameleon.net/blog/index.php?feed/rss2/xslt" ?><rss version="2.0"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:wfw="http://wellformedweb.org/CommentAPI/"
  xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
  <title>EKAMELEON - DevBlog ActionScript &amp; ECMAScript</title>
  <link>http://www.ekameleon.net/blog/index.php?</link>
  <description>DevBlog Flex - AIR - ActionScript3 - Flash Media Interactive Server - ECMAScript</description>
  <language>fr</language>
  <pubDate>Thu, 24 Jul 2008 14:58:57 +0200</pubDate>
  <copyright></copyright>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Dotclear</generator>
  
    
  <item>
    <title>[VEGAS] A - Design Pattern d'inversion de contrôle - Généralités</title>
    <link>http://www.ekameleon.net/blog/index.php?post/2008/07/21/A-Design-Pattern-dinversion-de-controle-Generalites</link>
    <guid isPermaLink="false">urn:md5:40782f0dbdead584a9ee23ae9b1230bb</guid>
    <pubDate>Tue, 22 Jul 2008 00:05:00 +0200</pubDate>
    <dc:creator>eKameleon</dc:creator>
        <category>VEGAS</category>
        <category>andromedas</category><category>as3</category><category>asgard</category><category>config</category><category>data</category><category>deserialize</category><category>design_pattern</category><category>eden</category><category>flex</category><category>io</category><category>IoC</category><category>json</category><category>serialize</category><category>vegas</category>    
    <description>&lt;p&gt;&lt;strong&gt;IoC&lt;/strong&gt;&amp;nbsp;? &lt;strong&gt;Injection de dépendance&lt;/strong&gt;&amp;nbsp;? &lt;strong&gt;Conteneur Léger&lt;/strong&gt; ... depuis quelques temps maintenant nous entendons parler de ce &lt;strong&gt;Design Pattern&lt;/strong&gt; très puissant qui révolutionne la construction des applications orientées objets. Ce &lt;strong&gt;Design Pattern&lt;/strong&gt; est vraiment pour moi indispensable une fois bien maitrisé et permet d'aller loin, très loin&amp;nbsp;!&lt;/p&gt;


&lt;p&gt;Depuis plusieurs mois maintenant je me suis lancé dans la construction de ma propre implémentation de ce pattern en m'inspirant d'une part de ce qu'il se fait de mieux à l'heure actuelle dans ce domaine ( Spring, Parsley, etc..) mais surtout des problèmes et besoins que je peux rencontrer chaque jour dans mes productions. Je remercie d'ailleurs tous ceux qui ont pris le temps de me supporter et de prendre le temps de poser un oeil sur mon code et au final qui m'ont aidé à aller au bout d'une version 1 finale (ou presque.. je finiolle :D ) de VEGAS et ses extensions.&lt;/p&gt;


&lt;p&gt;La version &lt;strong&gt;AS3&lt;/strong&gt; de &lt;strong&gt;VEGAS&lt;/strong&gt; est composée de plusieurs extensions très solides et spécialisées. Mais &lt;strong&gt;AndromedAS&lt;/strong&gt; avec ses outils d'&lt;strong&gt;IoC&lt;/strong&gt;, etc. est devenu le noyau dure du framework pour créer avec facilité une RIA moderne et fonctionnelle aussi bien dans Flash, Flex, ou dans une application &lt;strong&gt;AIR&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;Je commence donc ici par un premier chapitre de mon énorme article basé sur le &lt;strong&gt;Design Pattern IoC&lt;/strong&gt; dans &lt;strong&gt;VEGAS&lt;/strong&gt; qui va se découper en plusieurs parties ici sur ce blog et qui finira au bout du compte en livre opensource disponible très prochainement sur les pages officielles du projet et aussi sur Google Documents. J'ai encore pas mal de fonctionnalités à documenter car la bibliothèque &lt;strong&gt;IoC&lt;/strong&gt; s'est énormément étoffée ces derniers mois (pour la bonne cause).&lt;/p&gt;


&lt;p&gt;J'espère que cette introduction, vous permettra de vous faire une idée clair et précise des bases du pattern &lt;strong&gt;IoC&lt;/strong&gt; mais surtout de l'orientation que j'ai pu prendre pour l'implémenter. Cet article reste ouvert à tous commentaires et s'accompagnera très bientôt d'une seconde partie qui précisera le DOM très complet des définitions d'objets utilisée par le conteneur léger &lt;strong&gt;IoC&lt;/strong&gt; pour créer des objets dans une application.&lt;/p&gt;


&lt;p&gt;Comme toujours, je suis toute personne pouvant m'aider à accélérer le processus de traduction de cet article en anglais.&lt;/p&gt;


&lt;p&gt;Pour tout ceux qui sont pressés de savoir la suite, vous pouvez me contacter pour que je vous donne en attendant de la communiquer ouvertement sur ce blog, l'url des autres parties (en construction) de ce tutoriel assez imposant (80 pages pour le moment sur &lt;strong&gt;Google Documents&lt;/strong&gt;)&lt;/p&gt;


&lt;p&gt;A noter que vous trouverez les sources des exemples ci-dessous dans le repository SVN du projet&amp;nbsp;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://svn1.cvsdude.com/osflash/vegas/AS3/trunk/bin/test/andromeda/ioc/&quot;&gt;http://svn1.cvsdude.com/osflash/vegas/AS3/trunk/bin/test/andromeda/ioc/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://svn1.cvsdude.com/osflash/vegas/AS3/trunk/bin/test/asgard/net/&quot;&gt;http://svn1.cvsdude.com/osflash/vegas/AS3/trunk/bin/test/asgard/net/&lt;/a&gt; (3 exemples d'utilisation de la classe ECMAObjectLoader)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Pour ceux qui débarquent dans l'aventure, et qui ne savent pas encore ce que représente VEGAS, comment l'installer etc.. Je vous propose d'aller faire un tour rapide sur le Google Code du projet&amp;nbsp;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://code.google.com/p/vegas/&quot;&gt;http://code.google.com/p/vegas/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://code.google.com/p/vegas/wiki/InstallVEGASwithSVN&quot;&gt;http://code.google.com/p/vegas/wiki/InstallVEGASwithSVN&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Pour toutes vos questions sur VEGAS et ses extensions n'hésitez pas à vous inscrire sur le Google Groups&amp;nbsp;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;VEGASoS&amp;nbsp;: &lt;a href=&quot;http://groups.google.com/group/vegasos&quot;&gt;http://groups.google.com/group/vegasos&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Enfin pour suivre le projet au mieux je peux vous proposer de consulter la page officielle de VEGAS sur &lt;strong&gt;Ohloh&lt;/strong&gt;&amp;nbsp;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://www.ohloh.net/projects/vegas&quot;&gt;http://www.ohloh.net/projects/vegas&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Il est temps maintenant de démarrer cet article sur le &lt;strong&gt;Design Pattern d'IoC&lt;/strong&gt; et je vous promets la suite de cet article d'ici peu de temps &lt;img src=&quot;/blog/themes/default/smilies/wink.png&quot; alt=&quot;;)&quot; class=&quot;smiley&quot; /&gt;&lt;/p&gt;    &lt;h2&gt;1 - Définitions&lt;/h2&gt;


&lt;h3&gt;1-1 - Injection de dépendance (Dependency Injection)&lt;/h3&gt;


&lt;p&gt;Le design pattern &quot;&lt;strong&gt;Dependency injection (DI)&lt;/strong&gt;&quot; se réfère à la pratique de l'injection de code dans une application. Les classes ne sont pas responsables dans l'instanciation des autres classes dont elles ont besoin. Les objets sont &quot;&lt;strong&gt;injectés&lt;/strong&gt;&quot; au moment de la construction ou de l'initialisation de l'instance qui les utilise.&lt;/p&gt;


&lt;p&gt;Ce modèle de conception consiste en plusieurs classes ou objets qui collaborent les uns avec les autres. Nous pouvons aussi parler de la notion de dépendance entre les objets.&lt;/p&gt;


&lt;p&gt;Il existe plusieurs stratégies pour appliquer ce modèle de conception. Voyons donc de plus prêt les formes d'injection de dépendance existantes en général dans un code orienté objet.&lt;/p&gt;


&lt;h4&gt;Hard-coding dependencies&amp;nbsp;:&lt;/h4&gt;


&lt;p&gt;La classe crée en interne ses propres dépendances. Cette technique est la plus simple pour gérer une dépendance mais elle reste la moins souple de toutes.&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Exemple :&lt;/strong&gt;&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;package&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;class&lt;/span&gt; Writer
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; Writer&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; write&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;message&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; Pen&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;.write&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;message&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;



&lt;p&gt;Dans l'exemple précédent la classe &lt;strong&gt;Writer&lt;/strong&gt; utilise dans sa méthode &lt;strong&gt;write(message:String)&lt;/strong&gt; un objet de type &lt;strong&gt;Pen&lt;/strong&gt;. Cette méthode est donc dépendante d'un objet de type &lt;strong&gt;Pen&lt;/strong&gt; pour fonctionner.&lt;/p&gt;


&lt;p&gt;Le code est en effet très simple mais le fait de créer directement l'objet de type &lt;strong&gt;Pen&lt;/strong&gt; dans la méthode limite très vite le champ d'action de la classe et toutes évolutions de celle-ci par la suite. En cas de changement il faudra modifier directement le code dans la classe ce qui n'est pas forcément très pratique.&lt;/p&gt;


&lt;h4&gt;Looking up dependencies&amp;nbsp;:&lt;/h4&gt;


&lt;p&gt;Cette stratégie nécessite un contexte. La classe appelle un objet et utilise ses méthodes et attributs selon ses besoins. Le contexte est un objet externe qui contient donc toutes les dépendances.&lt;/p&gt;


&lt;p&gt;Voici un petit exemple pour illustrer cette implémentation&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;package&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;class&lt;/span&gt; Writer
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; Writer&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; write&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;message&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; context&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Tools = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; Tools&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
            context.getPen&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;.write&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;message&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;h4&gt;Constructor injection&amp;nbsp;:&lt;/h4&gt;


&lt;p&gt;L'injection par constructeur est une approche simple et classique. Cette approche du modèle utilise une classe qui possède une fonction constructeur avec des paramètres pour chaque dépendance que l'on souhaite définir.&lt;/p&gt;


&lt;p&gt;Les dépendances sont transmises au moment de l'instanciation de la classe.&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Exemple :&lt;/strong&gt;&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;package&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;class&lt;/span&gt; Writer
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; Writer&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; pen&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Pen &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            _pen = pen ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; _pen&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Pen ;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; write&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;message&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            _pen.write&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;message&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Dans cet exemple la fonction constructeur &lt;strong&gt;Writer( pen:Pen )&lt;/strong&gt; permet d'injecter au moment de la création d'une instance de type &lt;strong&gt;Writer&lt;/strong&gt; la référence d'un objet de type &lt;strong&gt;Pen&lt;/strong&gt; qui permettra à la méthode &lt;strong&gt;write()&lt;/strong&gt; de fonctionner correctement.&lt;/p&gt;


&lt;h4&gt;Setter Injection&amp;nbsp;:&lt;/h4&gt;


&lt;p&gt;Dans cette approche la classe possède des propriétés qui lui permettent de définir chacune de ses dépendances (attributs ou méthodes publiques).&lt;/p&gt;


&lt;p&gt;Les dépendances sont définies après la création d'une instance de cette classe.&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Exemple 1 :&lt;/strong&gt; &lt;em&gt;Avec une méthode ou un attribut publique de base.&lt;/em&gt;&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;package&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;class&lt;/span&gt; Writer
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; Writer&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; pen&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Pen ;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; setPen&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; p&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Pen &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;this&lt;/span&gt;.pen = p ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; write&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;message&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            pen.write&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;message&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Dans cet exemple la méthode '&lt;strong&gt;setPen(p:Pen)&lt;/strong&gt;' permet d'injecter dans les instance de la classe &lt;strong&gt;Writer&lt;/strong&gt; tout objet de type &lt;strong&gt;Pen&lt;/strong&gt; nécessaire au bon fonctionnement de la méthode &lt;strong&gt;write()&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Exemple 2 :&lt;/strong&gt; &lt;em&gt;Avec une attribut virtuel (setter).&lt;/em&gt;&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;package&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;class&lt;/span&gt; Writer
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; Writer&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; _pen&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Pen ;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;set&lt;/span&gt; pen&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; p&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Pen &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            _pen = p ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; write&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;message&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            _pen.write&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;message&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Dans cet exemple la propriété virtuelle '&lt;strong&gt;pen&lt;/strong&gt;' permet d'injecter dans les instance de la classe &lt;strong&gt;Writer&lt;/strong&gt; tout objet de type Pen nécessaire au bon fonctionnement de la méthode &lt;strong&gt;write()&lt;/strong&gt;.&lt;/p&gt;


&lt;h4&gt;Interface Injection&amp;nbsp;:&lt;/h4&gt;


&lt;p&gt;Cette méthode s'utilise de la même manière que les principes de  &lt;strong&gt;Setter Injection&lt;/strong&gt; ou de &lt;strong&gt;Constructor injection&lt;/strong&gt; mais en typant la dépendance (propriétés, arguments) avec une interface spécifique&amp;nbsp;:&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Exemple :&lt;/strong&gt;&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;package&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;class&lt;/span&gt; Writer
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; Writer&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
             &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; _pen&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;IPen ;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;get&lt;/span&gt; pen&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;IPen
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;return&lt;/span&gt; _pen ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;set&lt;/span&gt; pen&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; p&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;IPen &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            _pen = p ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; write&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;message&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;_pen &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;as&lt;/span&gt; IPen&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;.write&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;message&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;h3&gt;1-2 - Inversion de contrôle&lt;/h3&gt;


&lt;pre&gt;Le modèle de conception d'&lt;strong&gt;Inversion de contrôle&lt;/strong&gt;, ou plus simplement appelé &lt;strong&gt;IoC&lt;/strong&gt; (L'autre nom du modèle &lt;strong&gt;Dependency injection&lt;/strong&gt;) définit un ensemble de techniques de programmation dans lesquels le flux de contrôle du système et de ses objets est inversé par rapport à une technique traditionnelle de création d'une application et de ses interactions.&lt;/pre&gt;


&lt;p&gt;Le modèle de conception d'inversion de contrôle se base sur le &quot;&lt;a href=&quot;http://en.wikipedia.org/wiki/Hollywood_Principle&quot; hreflang=&quot;en&quot;&gt;Hollywood Principle&quot;&amp;nbsp;: &quot;don't call us, we will call you&lt;/a&gt;&quot;&amp;nbsp;: &lt;em&gt;&lt;strong&gt;«&amp;nbsp;Ne nous appelez pas, c’est nous qui vous appellerons. »&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;


&lt;p&gt;Le principe est simple, il indique un framework d'application qui n'a pas besoin d'être appelé pour faire fonctionner l'application, c'est le framework lui même qui s'occupe de créer les interactions entre les objets (dans la limite du possible).&lt;/p&gt;


&lt;p&gt;&lt;img src=&quot;http://www.ekameleon.net/blog/public/images/tutoriaux/IoC/ioc_hollywood_principle.gif&quot; alt=&quot;Inversion of control representation&quot; /&gt;&lt;/p&gt;


&lt;p&gt;Ce modèle favorise la programmation en &quot;&lt;strong&gt;couches&lt;/strong&gt;&quot;. Cette programmation permet de séparer chaque élément d'une application et de travailler sur chacun de façon indépendante et ensuite de les lier les uns aux autres très simplement en ayant le moins de dépendances possible au départ. C'est donc au framework de lier chaque couche les unes avec les autres le moment venu en injectant toutes les dépendances dans l'objet qui en aura besoin.&lt;/p&gt;


&lt;h3&gt;1-3 - Conteneurs basés sur le modèle d'inversion de contrôle.&lt;/h3&gt;


&lt;p&gt;Un conteneur d'inversion de contrôle est une infrastructure d'application qui fournit de nombreux services indispensables pour créer et faire vivre une application. Voici les principaux services d'un conteneur &lt;strong&gt;IoC&lt;/strong&gt; classique&amp;nbsp;:&lt;/p&gt;


&lt;h4&gt;Lookup&amp;nbsp;:&lt;/h4&gt;


&lt;p&gt;Le conteneur permet de stocker ou créer des références pour tous les objets de l'application. Le conteneur est donc également considéré comme une &quot;fabrique&quot; (factory) d'application.&lt;/p&gt;


&lt;h4&gt;Lifecycle management&amp;nbsp;:&lt;/h4&gt;


&lt;p&gt;Le cycle de vie des objets dans une application est géré par le conteneur. Le conteneur est capable de créer des nouveaux objets, d'injecter automatiquement des valeurs prédéfinies dans les propriétés d'une instance au moment de sa création, d'invoquer des méthodes spécifiques au moment de l'initialisation et de la destruction des objets, etc.&lt;/p&gt;


&lt;h4&gt;Configuration&amp;nbsp;:&lt;/h4&gt;


&lt;p&gt;Les objets de l'application peuvent être configurés simplement via des données externes sans avoir à recompiler l'application; Il est donc possible d'utiliser des données au format &lt;strong&gt;eden&lt;/strong&gt;, &lt;strong&gt;JSON&lt;/strong&gt; ou &lt;strong&gt;XML&lt;/strong&gt; pour créer la fabrique et initialiser l'application.&lt;/p&gt;


&lt;h4&gt;Dependency resolution&amp;nbsp;:&lt;/h4&gt;


&lt;p&gt;Le conteneur ne se contente pas de gérer et configurer les objets de l'application avec des types simples, il permet aussi de gérer les relations et dépendances que peuvent avoir les objets les uns avec les autres.&lt;/p&gt;


&lt;h3&gt;1-4 -Définition d'objet dans un conteneur IoC.&lt;/h3&gt;


&lt;p&gt;Une &lt;strong&gt;définition d'objet&lt;/strong&gt; est un objet qui va permettre de créer un nouvel objet dans une application avec  la &lt;strong&gt;fabrique IoC&lt;/strong&gt;. Cette définition d'objet peut être considérée comme un &lt;strong&gt;&quot;mode d'emploi&quot;&lt;/strong&gt; défini au préalable par les développeurs de l'application qui utilise ce conteneur.&lt;/p&gt;


&lt;p&gt;Ce mode d'emploi contient entre autre&amp;nbsp;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;un identifiant qui permet d'enregistrer la définition dans un conteneur léger et par la suite de créer des objets,&lt;/li&gt;
&lt;li&gt;le type de l'objet que l'on souhaite créer,&lt;/li&gt;
&lt;li&gt;les paramètres que l'on souhaite passer dans le constructeur,&lt;/li&gt;
&lt;li&gt;les valeurs par défaut que l'on souhaite appliquer sur l'objet (propriétés et méthodes),&lt;/li&gt;
&lt;li&gt;le nom de la méthode que l'on souhaite exécuter une fois l'objet créé pour l'initialiser le rendre actif dans l'application,&lt;/li&gt;
&lt;li&gt;injecter les dépendances avec les autres objets définis eux aussi dans la fabrique,&lt;/li&gt;
&lt;li&gt;etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;La définition d'objet peut donner d'autres informations sur la stratégie utilisée par la fabrique pour créer l'objet ou sur la nature de cet objet dans le cycle de vie de l'application (singleton, prototype..).&lt;/p&gt;


&lt;p&gt;Si l'on devait réduire à sa plus simple expression la définition d'un &lt;strong&gt;conteneur IoC&lt;/strong&gt;, nous pourrions dire qu'il se compose d'une collection de &lt;strong&gt;définitions d'objets&lt;/strong&gt; qui permettent de structurer efficacement et de façon solide une application tout au long de son cycle de vie.&lt;/p&gt;


&lt;h2&gt;2 - Configuration d'un conteneur IoC.&lt;/h2&gt;


&lt;p&gt;Pour créer et surtout remplir convenablement un conteneur &lt;strong&gt;IoC&lt;/strong&gt;, il est possible d'utiliser tout simplement du code classique, mais sur des applications de moyenne ou grande taille cette technique peut s'avérer rapidement très fastidieuse et peu souple. Surtout qu'à chaque ajout dans le conteneur il faudra la plupart du temps relancer la compilation du programme.&lt;/p&gt;


&lt;p&gt;Le modèle de conception d'inversion de contrôle à pour but de proposer des outils simples et d'optimiser efficacement le flux de production d'une application.&lt;/p&gt;


&lt;p&gt;Il devient donc rapidement indispensable de compléter celui-ci par une gestion dynamique de son contenu. Dans la plupart des frameworks utilisant un design pattern &lt;strong&gt;IoC&lt;/strong&gt; nous retrouvons un déploiement des applications au &lt;a href=&quot;http://en.wikipedia.org/wiki/Runtime&quot;&gt;runtime&lt;/a&gt; (après compilation) via des fichiers de configuration externes souvent au format &lt;strong&gt;XML&lt;/strong&gt; (exemple avec le framework &lt;strong&gt;Spring.NET&lt;/strong&gt; ou &lt;strong&gt;Spring JAVA&lt;/strong&gt;).&lt;/p&gt;


&lt;p&gt;L'utilisation d'un ou plusieurs fichiers externes de configuration pour gérer une application reste la solution la plus souple. En intervenant après le lancement de l'application, il est possible de modifier le contenu du conteneur sans avoir à recompiler à chaque fois l'application. Nous parlerons alors d'un &lt;strong&gt;&quot;conteneur léger&quot;&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;De plus, il est possible avec un moteur de configuration avancé de faire évoluer l'application dynamiquement en fournissant au conteneur uniquement les définitions d'objets nécessaires et en alimentant régulièrement le conteneur avec de nouvelles définitions d'objets au fil du temps selon les besoins.&lt;/p&gt;


&lt;h3&gt;2-1 - Fichier de configuration basé sur le format de donnée &quot;eden&quot;.&lt;/h3&gt;


&lt;p&gt;Le modèle de conception &lt;strong&gt;IoC AndromedAS&lt;/strong&gt; propose une fabrique &lt;strong&gt;IoC&lt;/strong&gt; basée sur des fichiers de configuration au format &lt;strong&gt;&lt;a href=&quot;http://code.google.com/p/edenrr/&quot;&gt;eden&lt;/a&gt;&lt;/strong&gt;&amp;nbsp;: &lt;strong&gt;ECMAScript Data Exchange Notation&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;eden&lt;/strong&gt; est à la base un outil de &lt;strong&gt;sérialisation/désérialisation&lt;/strong&gt; d'objets via des données au format texte et sur une notation basée sur la norme &lt;strong&gt;ECMAScript&lt;/strong&gt; écrit par &lt;strong&gt;Zwetan Kjukov&lt;/strong&gt;. Cette notation permet l'échange de données entre un client et un serveur mais aussi la mise en place de configurations simples ou complexes dans nos applications.&lt;/p&gt;


&lt;p&gt;Une des grandes forces du format &lt;strong&gt;eden&lt;/strong&gt; est de proposer une structure de données basée sur un format texte très simple à utiliser et que l'on peut &lt;em&gt;copier/coller&lt;/em&gt; très simplement pour l'utiliser directement dans un code &lt;strong&gt;ActionScript&lt;/strong&gt; ou &lt;strong&gt;Javascript&lt;/strong&gt; sans avoir à traiter la chaine de caractère récupérée dans un fichier de texte externe par exemple.&lt;/p&gt;


&lt;p&gt;Il peut s'avérer facile de comparer après un bref coup d'œil le format &lt;a href=&quot;http://code.google.com/p/edenrr/&quot;&gt;eden&lt;/a&gt; avec le format &lt;a href=&quot;http://www.json.org/jsonfr.html&quot;&gt;JSON&lt;/a&gt; mais ce dernier reste vraiment pauvre par rapport à toutes les fonctionnalités que propose &lt;strong&gt;eden&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;Le format &lt;strong&gt;eden&lt;/strong&gt; accepte de nombreux types&amp;nbsp;:&lt;/p&gt;


&lt;h4&gt;Array&lt;/h4&gt;


&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;//eden&lt;/span&gt;
&amp;nbsp;
    a = &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;1&lt;/span&gt;, &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;2&lt;/span&gt;, &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;3&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt; ;
    &lt;span style=&quot;color: #004993;&quot;&gt;b&lt;/span&gt; = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;&lt;/pre&gt;


&lt;h4&gt;Boolean&lt;/h4&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;//eden&lt;/span&gt;
&amp;nbsp;
      &lt;span style=&quot;color: #004993;&quot;&gt;b&lt;/span&gt; = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;true&lt;/span&gt;;
      &lt;span style=&quot;color: #004993;&quot;&gt;c&lt;/span&gt; = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;false&lt;/span&gt;;
      &lt;span style=&quot;color: #004993;&quot;&gt;d&lt;/span&gt; = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;Boolean&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;; &lt;span style=&quot;color: #009900;&quot;&gt;// d = false&lt;/span&gt;&lt;/pre&gt;


&lt;h4&gt;Date&lt;/h4&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;//eden&lt;/span&gt;
&amp;nbsp;
      d1 = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;Date&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
      d2 = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;Date&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;1974&lt;/span&gt;, &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;2&lt;/span&gt;, &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;30&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/pre&gt;


&lt;h4&gt;Null&lt;/h4&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;//eden&lt;/span&gt;
&amp;nbsp;
      x1 =&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;null&lt;/span&gt; ;&lt;span style=&quot;color: #009900;&quot;&gt;// x1 = null&lt;/span&gt;
      x2 ;  &lt;span style=&quot;color: #009900;&quot;&gt;//x2 = undefined&lt;/span&gt;&lt;/pre&gt;


&lt;h4&gt;Number&lt;/h4&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;//eden&lt;/span&gt;
&amp;nbsp;
      n1 = &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;123&lt;/span&gt;;
      n2 = &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;1.23&lt;/span&gt;;
      n3 = 1e5;
      n4 = 0xff;
      n5 = &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;-123&lt;/span&gt;;
      n6 = &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;-&lt;/span&gt;n2; &lt;span style=&quot;color: #009900;&quot;&gt;// n6 = -1.23&lt;/span&gt;
      n7 = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;Number&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;100&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;; &lt;span style=&quot;color: #009900;&quot;&gt;// n7 = 100&lt;/span&gt;&lt;/pre&gt;


&lt;h4&gt;Object&lt;/h4&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;//eden&lt;/span&gt;
&amp;nbsp;
      o1 = &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; a&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;1&lt;/span&gt;, &lt;span style=&quot;color: #004993;&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;2&lt;/span&gt;, &lt;span style=&quot;color: #004993;&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;3&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;;
      o2 = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;Object&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;; &lt;span style=&quot;color: #009900;&quot;&gt;// o2 = 5&lt;/span&gt;
      o3 = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;Object&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/pre&gt;


&lt;h4&gt;String&lt;/h4&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;//eden&lt;/span&gt;
&amp;nbsp;
    s1 = &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;hello world&amp;quot;&lt;/span&gt;;
    s2 = &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;unicode supported ♠♣♥♦&amp;quot;&lt;/span&gt;;
    s3 = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;hello world&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;; &lt;span style=&quot;color: #009900;&quot;&gt;// s3 = &amp;quot;hello world&amp;quot;&lt;/span&gt;&lt;/pre&gt;


&lt;h4&gt;Types customs définis par l'utilisateur&lt;/h4&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;//eden&lt;/span&gt;
&amp;nbsp;
    v1 = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; Version&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;1&lt;/span&gt;, &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;2&lt;/span&gt;, &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;3&lt;/span&gt;, &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;4&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    v2 = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; system.Version&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;1&lt;/span&gt;, &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;2&lt;/span&gt;, &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;3&lt;/span&gt;, &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;4&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/pre&gt;


&lt;p&gt;Il permet également les fonctionnalités suivantes&amp;nbsp;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fonctionne avec n'importe quel client ou serveur basé sur la norme &lt;a href=&quot;http://www.ecma-international.org/publications/standards/Ecma-262.htm&quot;&gt;ECMA-262&lt;/a&gt; (&lt;strong&gt;Javascript&lt;/strong&gt;, &lt;strong&gt;ActionScript&lt;/strong&gt;, &lt;strong&gt;JScript&lt;/strong&gt;, Flash Media Server__, etc.)&lt;/li&gt;
&lt;li&gt;Fonctionne avec la plupart des serveurs de données existant qui manipulent les chaînes de caractères.&lt;/li&gt;
&lt;li&gt;Appel de fonctions et de méthodes sur les objets.&lt;/li&gt;
&lt;li&gt;Gestion des données sécurisées avec isolation des scopes des objets et &quot;white list&quot; d'autorisation pour les types d'objets customs (types d'objets créés par le développeur dans son application).&lt;/li&gt;
&lt;li&gt;Possibilité de définir plusieurs valeurs dans une même chaine de caractère.&lt;/li&gt;
&lt;li&gt;Supporte les commentaires sur une ligne avec le séparateur &lt;strong&gt;//&lt;/strong&gt; ou les commentaires multilignes avec les séparateurs &lt;strong&gt;/* */&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Il serait possible de créer des fichiers de configuration au format &lt;strong&gt;XML&lt;/strong&gt; peut être plus classiques et plus &quot;standard&quot; si l'on compare les différents &lt;strong&gt;frameworks IoC&lt;/strong&gt; actuels. Maintenant je trouve personnellement trop &quot;&lt;em&gt;verbeux&lt;/em&gt;&quot; et très limitée la notation &lt;strong&gt;XML&lt;/strong&gt; qui propose des fichiers de configurations complexes et qui entraine un énorme travail de &lt;strong&gt;parsing&lt;/strong&gt; au niveau de l'application pour reproduire une partie infime des possibilités du parseur &lt;strong&gt;eden&lt;/strong&gt;. La grande force de &lt;strong&gt;eden&lt;/strong&gt; est de conserver dans le document de configuration, le type de tous les objets sans avoir à définir à chaque fois celui-ci.&lt;/p&gt;


&lt;p&gt;Voyons pas exemple rapidement la différence entre une même définition d'objet définie par un schéma &lt;strong&gt;XML&lt;/strong&gt; et un objet au format &lt;strong&gt;eden&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;Prenons une classe simple pour illustrer notre exemple une classe &lt;strong&gt;test.User&lt;/strong&gt; très simple écrite en &lt;strong&gt;ActionScript 3&lt;/strong&gt;&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;package&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;test&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
    &lt;span style=&quot;color: #3f5fbf;&quot;&gt;/**
     * The User class.
     */&lt;/span&gt;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;class&lt;/span&gt; User
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #3f5fbf;&quot;&gt;/**
         * Creates a new User instance.
         */&lt;/span&gt;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; User&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; pseudo&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;null&lt;/span&gt;, &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;null&lt;/span&gt; , address&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Address = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;null&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;this&lt;/span&gt;.pseudo  = pseudo ;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt;    = &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; ;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;this&lt;/span&gt;.address = address ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #3f5fbf;&quot;&gt;/**
         * The Address reference of this object.
         */&lt;/span&gt;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; address&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Address ;
&amp;nbsp;
        &lt;span style=&quot;color: #3f5fbf;&quot;&gt;/**
         * The age of the user.
         */&lt;/span&gt;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; age&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Number&lt;/span&gt; ;
&amp;nbsp;
        &lt;span style=&quot;color: #3f5fbf;&quot;&gt;/**
          * The city of the user.
          */&lt;/span&gt;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; city&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; ;
&amp;nbsp;
        &lt;span style=&quot;color: #3f5fbf;&quot;&gt;/**
         * The name of the User.
         */&lt;/span&gt;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; ;
&amp;nbsp;
        &lt;span style=&quot;color: #3f5fbf;&quot;&gt;/**
         * Initialize the User.
         */&lt;/span&gt;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; initialize&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;this&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot; initialize.&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Voyons tout d'abord un exemple de définition d'objet basé sur un schéma &lt;strong&gt;XML&lt;/strong&gt; classique proche du DOM &lt;strong&gt;Spring.NET&lt;/strong&gt;&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;xml&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;objects&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&amp;nbsp;
    &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;object&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;name&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;address&amp;quot;&lt;/span&gt;  &lt;span style=&quot;color: #000066;&quot;&gt;type&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;test.Address&amp;quot;&lt;/span&gt; &lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;constructor-arg&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;index&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;0&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;value&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;34 xxx street&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/object&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&amp;nbsp;
    &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;object&lt;/span&gt;
         name        = &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;user&amp;quot;&lt;/span&gt;
         type        = &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;myPackage.User&amp;quot;&lt;/span&gt;
        init-method = &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;initialize&amp;quot;&lt;/span&gt;
    &lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;constructor-arg&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;index&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;0&amp;quot;&lt;/span&gt; value = &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;ekameleon&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;constructor-arg&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;index&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;1&amp;quot;&lt;/span&gt; value = &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;ALCARAZ&amp;quot;&lt;/span&gt;  &lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;constructor-arg&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;index&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;2&amp;quot;&lt;/span&gt; ref   = &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;address&amp;quot;&lt;/span&gt;  &lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;property&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;name&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;age&amp;quot;&lt;/span&gt;  &lt;span style=&quot;color: #000066;&quot;&gt;value&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;31&amp;quot;&lt;/span&gt; &lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;property&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;name&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;city&amp;quot;&lt;/span&gt;  &lt;span style=&quot;color: #000066;&quot;&gt;value&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;marseille&amp;quot;&lt;/span&gt; &lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
&amp;nbsp;
    &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/object&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/objects&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Voyons le même exemple (ou presque) avec une notation &lt;strong&gt;eden&lt;/strong&gt;&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;objects =
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;
&amp;nbsp;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        id         &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;user&amp;quot;&lt;/span&gt; ,
        &lt;span style=&quot;color: #004993;&quot;&gt;type&lt;/span&gt;       &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;myPackage.User&amp;quot;&lt;/span&gt; ,
        &lt;span style=&quot;color: #004993;&quot;&gt;init&lt;/span&gt;       &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;initialize&amp;quot;&lt;/span&gt; ,
        &lt;span style=&quot;color: #004993;&quot;&gt;arguments&lt;/span&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; 
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt; 
             &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;value&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;ekameleon&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt; , 
             &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;value&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;ALCARAZ&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt; , 
             &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;value&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;test&lt;/span&gt;.Address&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;34 xxx street&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt; 
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt; 
        ,
        properties &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;
           &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;age&amp;quot;&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;value&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;31&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt; ,
           &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;city&amp;quot;&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;value&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;marseille&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt; ;&lt;/pre&gt;


&lt;p&gt;A noter qu'il est possible d'utiliser des objets directement dans le code de vos applications pour alimenter le &lt;strong&gt;conteneur IoC&lt;/strong&gt; sans passer par un fichier de configuration au format texte. Il est également possible de créer cet objet via un service web &lt;strong&gt;PHP&lt;/strong&gt;, &lt;strong&gt;JAVA&lt;/strong&gt;, &lt;strong&gt;Pyhon&lt;/strong&gt; et de le renvoyer vers le client via le protocole texte classique (&lt;strong&gt;eden&lt;/strong&gt; ou &lt;strong&gt;JSON&lt;/strong&gt;) ou le &lt;strong&gt;protocol AMF&lt;/strong&gt; (&lt;strong&gt;Action Message Format&lt;/strong&gt; - &lt;strong&gt;Flash Remoting&lt;/strong&gt;).&lt;/p&gt;


&lt;h3&gt;2-2 - Autres alternatives avec JSON&amp;nbsp;?&lt;/h3&gt;


&lt;p&gt;Même si je vous conseille vivement d'utiliser le format &lt;strong&gt;eden&lt;/strong&gt; pour créer vos fichiers de configuration, si vous désirez absolument utiliser un format &lt;strong&gt;JSON&lt;/strong&gt; pour alimenter le conteneur &lt;strong&gt;IoC&lt;/strong&gt;, dans &lt;strong&gt;VEGAS&lt;/strong&gt;, j'ai implémenté une adaptation de la &lt;strong&gt;classe &lt;a href=&quot;http://www.json.org/&quot;&gt;JSON officielle&lt;/a&gt;. La classe &lt;/strong&gt;vegas.string.JSON&lt;strong&gt; offre en plus des fonctionnalités classiques, la possibilité d'utiliser des nombres hexadécimaux &lt;/strong&gt;(0xFF...)&lt;strong&gt; et surtout elle permet de désérialiser&lt;/strong&gt; sans problème des expressions contenant des objets génériques définis avec ou &lt;strong&gt;sans double-quote&lt;/strong&gt; ou même avec des &lt;strong&gt;simple-quotes&lt;/strong&gt;&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; vegas.string.JSON ;
&amp;nbsp;
JSON.deserialize&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;prop&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; 0xFF0000 &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
JSON.deserialize&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;'prop'&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; 0x00FF00 &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
JSON.deserialize&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; prop &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; 0x0000FF &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;&lt;/pre&gt;


&lt;p&gt;Vous pouvez consulter pour plus d'information la documentation de la classe &lt;a href=&quot;http://www.ekameleon.net/vegas/docs/vegas/string/JSON.html&quot;&gt;vegas.string.JSON&lt;/a&gt; dans la référence &lt;strong&gt;AS3&lt;/strong&gt; de &lt;strong&gt;VEGAS&lt;/strong&gt; et ses extensions.&lt;/p&gt;


&lt;h3&gt;2-3 - Structure et DOM général des fichiers de configuration basés sur le format de donnée &quot;eden&quot;.&lt;/h3&gt;


&lt;p&gt;Voici la structure principale objet d'une configuration pour une fabrique &lt;strong&gt;IoC&lt;/strong&gt; dans le &lt;strong&gt;framework AndromedAS&lt;/strong&gt; (extension de &lt;strong&gt;VEGAS&lt;/strong&gt;)&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
    configuration : &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// only in the first configuration file&lt;/span&gt;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
         &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// ..&lt;/span&gt;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
    ,
    imports :
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;
        &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//..&lt;/span&gt;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;
    ,
    objects :
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;
        &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//..  &lt;/span&gt;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Il est aussi possible d'écrire plus simplement la structure précédente avec une chaine de caractère au format &lt;strong&gt;eden&lt;/strong&gt; avec la structure suivante&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript&quot;&gt;configuration =
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// only in the first file&lt;/span&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; ;
&amp;nbsp;
imports =
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;
    &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//..&lt;/span&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; ;
&amp;nbsp;
objects =
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;
    &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//..  &lt;/span&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; ;&lt;/pre&gt;


&lt;p&gt;L'attribut &lt;strong&gt;&quot;objects&quot;&lt;/strong&gt; est le plus important car il représente la collection (&lt;strong&gt;Array&lt;/strong&gt;) de toutes les &lt;strong&gt;définitions d'objets&lt;/strong&gt; que l'on souhaite insérer dans le &lt;strong&gt;conteneur IoC&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;Les attributs &lt;strong&gt;&quot;configuration&quot;&lt;/strong&gt; et &lt;strong&gt;&quot;imports&quot;&lt;/strong&gt; sont facultatifs et sont utilisés via une classe spéciale mais non obligatoire pour utiliser les fonctionnalités de base du conteneur. L'attribut &quot;&lt;strong&gt;configuration&lt;/strong&gt;&quot; sera utilisé uniquement dans le fichier principal de configuration utilisé pour lancer l'initialisation de la fabrique dans l'application.&lt;/p&gt;


&lt;p&gt;Pour en savoir plus sur ces attributs, vous pourrez consulter le &lt;strong&gt;chapitre C - Les attributs facultatifs &quot;configuration&quot; et &quot;imports&quot; dans les fichiers de configuration d'une fabrique IoC&lt;/strong&gt;. (Ce chapitre est en cours d'écriture et il arrivera très vite sur ce blog ;))&lt;/p&gt;


&lt;h2&gt;3 - La classe andromeda.ioc.factory.ECMAObjectFactory&lt;/h2&gt;


&lt;h3&gt;3-1 - Description&lt;/h3&gt;


&lt;p&gt;La classe ECMAObjectFactory est la classe principale du moteur d'injection de dépendance définie dans le package andromeda.ioc.*.&lt;/p&gt;


&lt;p&gt;Elle définit, à elle seule, le conteneur et la fabrique IOC qui sont utilisés par le framework pour gérer le contenu d'une application avec le Design Pattern d'Inversion de Contrôle.&lt;/p&gt;


&lt;p&gt;Cette classe possède un héritage riche, avec plusieurs niveaux d'héritage, qui lui procure plusieurs fonctionnalités importantes&amp;nbsp;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;ECMAObjectFactory&lt;/strong&gt; ( Classe principale du framework &lt;strong&gt;IoC&lt;/strong&gt; basée sur des &lt;strong&gt;définitions d'objet&lt;/strong&gt; au format &lt;strong&gt;ECMAScript&lt;/strong&gt; )&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ObjectFactory&lt;/strong&gt;&amp;nbsp;:&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ObjectDefinitionContainer&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Action&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SimpleAction&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;CoreEventDispatcher&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;CoreObject&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Object&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Cette classe implémente les interfaces&amp;nbsp;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;IObjectDefinitionContainer&lt;/strong&gt;&amp;nbsp;: Définit l'ensemble des méthodes permettant de gérer les définitions d'objets dans le conteneur &lt;strong&gt;IoC&lt;/strong&gt; (voir classe &lt;strong&gt;ObjectDefinitionContainer&lt;/strong&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;IObjectFactory&lt;/strong&gt;&amp;nbsp;: Définit l'ensemble des méthodes qui permettent la gestion et récupération des objets contenus dans la fabrique &lt;strong&gt;IoC&lt;/strong&gt; (voir classe &lt;strong&gt;ObjectFactory&lt;/strong&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;IFactory&lt;/strong&gt;&amp;nbsp;: Définit la méthode create() qui permet de générer un ensemble de définition d'objets nécessaires pour une application donnée (voir classe &lt;strong&gt;ECMAObjectFactory&lt;/strong&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;IAction&lt;/strong&gt;&amp;nbsp;: Définit une notion de &quot;process&quot; sur la fabrique. La classe notifie un évènement au début et à la fin de l'initialisation complète du conteneur.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;IRunnable&lt;/strong&gt;&amp;nbsp;: Définit que le conteneur peut être initialisé en exécutant simplement l'objet comme une commande avec la méthode &lt;strong&gt;run()&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;3-2 - Exemple d'utilisation en ActionScript ( &quot;hello world&quot; ).&lt;/h3&gt;


&lt;p&gt;Je vais illustrer l'utilisation de la fabrique &lt;strong&gt;IoC&lt;/strong&gt; &quot;&lt;strong&gt;ECMAObjectFactory&lt;/strong&gt;&quot; avec une initialisation simple basée sur simple objet de type &lt;strong&gt;Array&lt;/strong&gt; qui contient un ensemble d'objets génériques. Ces objets génériques permettent l'initialisation et l'injection de plusieurs &lt;strong&gt;définitions d'objets&lt;/strong&gt; et la création automatique de certains objets &quot;&lt;strong&gt;singleton&lt;/strong&gt;&quot; pendant l'initialisation du conteneur léger avec certaines &lt;strong&gt;définitions d'objets&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;L'exemple qui va suivre peut être testé aussi bien dans &lt;strong&gt;Flash CS3&lt;/strong&gt; que dans une application &lt;strong&gt;Flex&lt;/strong&gt; ou même une application basée sur la technologie &lt;strong&gt;AIR&lt;/strong&gt;. Cet exemple se base sur un bout de code saisi dans un calque sur la scène principale d'une animation dans &lt;strong&gt;Flash&lt;/strong&gt; mais il est très simple d'adapter ce bout de code pour l'utiliser dans un projet &lt;strong&gt;AS3&lt;/strong&gt; basé sur une classe &quot;&lt;strong&gt;main&lt;/strong&gt;&quot; d'application.&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; andromeda.ioc.factory.ECMAObjectFactory ;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; objects&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Array&lt;/span&gt; =
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        id        &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;my_format&amp;quot;&lt;/span&gt; ,
        &lt;span style=&quot;color: #004993;&quot;&gt;type&lt;/span&gt;      &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;flash.text.TextFormat&amp;quot;&lt;/span&gt; ,
        &lt;span style=&quot;color: #004993;&quot;&gt;arguments&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;arial&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt; , &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;24&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt; , &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;0xFEF292 &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt; , &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;true&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    ,
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        id         &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;my_field&amp;quot;&lt;/span&gt; ,
        &lt;span style=&quot;color: #004993;&quot;&gt;type&lt;/span&gt;       &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;flash.text.TextField&amp;quot;&lt;/span&gt;  ,
        properties &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;autoSize&amp;quot;&lt;/span&gt;          , &lt;span style=&quot;color: #004993;&quot;&gt;value&lt;/span&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;left&amp;quot;&lt;/span&gt;            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt; ,
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;defaultTextFormat&amp;quot;&lt;/span&gt; , ref    &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;my_format&amp;quot;&lt;/span&gt;       &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt; ,
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;text&amp;quot;&lt;/span&gt;              , &lt;span style=&quot;color: #004993;&quot;&gt;value&lt;/span&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;HELLO WORLD&amp;quot;&lt;/span&gt;     &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt; ,
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;x&amp;quot;&lt;/span&gt;                 , &lt;span style=&quot;color: #004993;&quot;&gt;value&lt;/span&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;10&lt;/span&gt;                &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt; ,
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;y&amp;quot;&lt;/span&gt;                 , &lt;span style=&quot;color: #004993;&quot;&gt;value&lt;/span&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;10&lt;/span&gt;                &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    ,
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        id               &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;root&amp;quot;&lt;/span&gt; ,
        &lt;span style=&quot;color: #004993;&quot;&gt;type&lt;/span&gt;             &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;flash.display.MovieClip&amp;quot;&lt;/span&gt;  ,
        factoryReference &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;#root&amp;quot;&lt;/span&gt; ,
        singleton        &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;true&lt;/span&gt; ,
        properties       &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;addChild&amp;quot;&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;arguments&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; ref&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;my_field&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt; ;
&amp;nbsp;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; factory&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;ECMAObjectFactory = ECMAObjectFactory.getInstance&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
factory.config.&lt;span style=&quot;color: #004993;&quot;&gt;root&lt;/span&gt; = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;this&lt;/span&gt; ;
&amp;nbsp;
factory.create&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; objects &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;&lt;/pre&gt;


&lt;p&gt;L'objet &quot;&lt;strong&gt;objects&lt;/strong&gt;&quot; de type &lt;strong&gt;Array&lt;/strong&gt; de configuration ci-dessus permet de définir 3 &lt;strong&gt;définitions d'objet&lt;/strong&gt;&amp;nbsp;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&quot;my_format&quot;&lt;/strong&gt;&amp;nbsp;: cette définition permet de créer des instances de types &lt;strong&gt;flash.text.TextFormat&lt;/strong&gt;, cette définition injecte des dépendances via la fonction constructeur de la classe pour initialiser l'objet.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&quot;my_field&quot;&lt;/strong&gt;&amp;nbsp;: cette définition permet de créer des champs de texte dynamiques de type &lt;strong&gt;flash.text.TextField&lt;/strong&gt; avec une initialisation de certains de ces attributs avec des injections de dépendance via l'attribut &quot;&lt;strong&gt;properties&lt;/strong&gt;&quot;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&quot;root&quot;&lt;/strong&gt;&amp;nbsp;: cette définition permet de créer une référence &lt;strong&gt;singleton&lt;/strong&gt; qui cible la scène principale de l'application définie dans la configuration de la fabrique &lt;strong&gt;IoC&lt;/strong&gt; (voir code ci-dessous) et d'attacher dessus le champ de texte dynamique &quot;&lt;strong&gt;my_field&lt;/strong&gt;&quot;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A noter que la définition d'objet &lt;strong&gt;&quot;root&quot;&lt;/strong&gt; utilise une stratégie spéciale de la &lt;strong&gt;fabrique IoC&lt;/strong&gt; qui lui permet de cibler dans une définition d'objet une référence de la scène principale définie dans le code ci-dessus avec la propriété &lt;strong&gt;root&lt;/strong&gt; de l'objet de config de la fabrique&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;factory.config.&lt;span style=&quot;color: #004993;&quot;&gt;root&lt;/span&gt; = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;this&lt;/span&gt; ;&lt;/pre&gt;


&lt;p&gt;&lt;strong&gt;Remarque :&lt;/strong&gt; La &lt;strong&gt;fabrique IoC&lt;/strong&gt; possède plusieurs types de stratégies pour créer un objet dans l'application avec une définition d'objet. Nous en parlerons dans le prochain chapitre consacré aux définitions d'objets (&lt;strong&gt;Chapitre B&lt;/strong&gt;, je suis en train de finaliser ce chapitre très long sur les &lt;strong&gt;définitions d'objets&lt;/strong&gt;...).&lt;/p&gt;


&lt;p&gt;L'exemple ci-dessus permet d'afficher très rapidement un champ de texte sur la scène d'une animation. Cet exemple nous montre bien l'utilisation d'une &lt;strong&gt;&quot;programmation en couches&quot;&lt;/strong&gt; qui permet d'isoler chaque objet d'une application et de travailler tranquillement sur chacun d'eux sans se soucier de leurs dépendances les uns avec les autres. C'est le conteneur léger et le framework qui se chargent de créer les objets et de les mettre en relations les uns avec les autres.&lt;/p&gt;


&lt;p&gt;Nous reprendrons dans le prochain chapitre cet exemple pour illustrer la technique utilisée pour chargée ce contexte de configuration avec un fichier au format texte externe (au format &lt;strong&gt;eden&lt;/strong&gt;).&lt;/p&gt;


&lt;h3&gt;3-3 - Inspection des méthodes de la classe ObjectDefinitionContainer, base du conteneur IOC (interface IObjectDefinitionContainer)&lt;/h3&gt;


&lt;p&gt;Voici l'ensemble des méthodes et propriétés définies par l'interface &lt;strong&gt;IObjectDefinitionContainer&lt;/strong&gt; implémentée par la classe &lt;strong&gt;EdenObjectFactory&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;&lt;img src=&quot;http://www.ekameleon.net/blog/public/images/tutoriaux/IoC/IObjectDefinition_properties.jpg&quot; alt=&quot;IObjectDefinition properties&quot; /&gt;&lt;/p&gt;


&lt;p&gt;Voici un exemple simple d'utilisation des méthodes définies ci-dessus&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;flash.text&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;TextField&lt;/span&gt; ;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;flash.text&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;TextFormat&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; andromeda.ioc.core.ObjectDefinition ;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; andromeda.ioc.core.ObjectDefinitionContainer ;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; andromeda.ioc.factory.ObjectFactory ;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; container&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;ObjectDefinitionContainer = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; ObjectFactory&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; context&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Object&lt;/span&gt; =
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    id         &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;my_field&amp;quot;&lt;/span&gt; ,
    &lt;span style=&quot;color: #004993;&quot;&gt;type&lt;/span&gt;       &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;flash.text.TextField&amp;quot;&lt;/span&gt; ,
    properties &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;defaultTextFormat&amp;quot;&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;value&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;TextFormat&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;verdana&amp;quot;&lt;/span&gt;, &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;11&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt; ,
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;selectable&amp;quot;&lt;/span&gt;        , &lt;span style=&quot;color: #004993;&quot;&gt;value&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;false&lt;/span&gt;                         &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt; ,
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;text&amp;quot;&lt;/span&gt;              , &lt;span style=&quot;color: #004993;&quot;&gt;value&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;hello world&amp;quot;&lt;/span&gt;                 &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt; ,
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;textColor&amp;quot;&lt;/span&gt;         , &lt;span style=&quot;color: #004993;&quot;&gt;value&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; 0xF7F744                      &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt; ,
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;x&amp;quot;&lt;/span&gt;                 , &lt;span style=&quot;color: #004993;&quot;&gt;value&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;100&lt;/span&gt;                           &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt; ,
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;y&amp;quot;&lt;/span&gt;                 , &lt;span style=&quot;color: #004993;&quot;&gt;value&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;100&lt;/span&gt;                           &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;        
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; definition&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;ObjectDefinition = ObjectDefinition.create&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; context &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
container.addObjectDefinition&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; definition &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; container.containsObjectDefinition&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;my_field&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// true&lt;/span&gt;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; container.getObjectDefinition&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;my_field&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// [ObjectDefinition]&lt;/span&gt;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; container.sizeObjectDefinition&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// 1&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; field&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;TextField&lt;/span&gt; = &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;container &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;as&lt;/span&gt; ObjectFactory&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;.getObject&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;my_field&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;as&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;TextField&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;addChild&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;field&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;&lt;/pre&gt;


&lt;p&gt;Dans cet exemple nous initialisons une &lt;strong&gt;définition d'objet&lt;/strong&gt; avec un objet générique simple qui permettra de générer avec la fabrique une instance de la classe &lt;strong&gt;TextField&lt;/strong&gt; spécifique qu'il sera très simple ensuite d'attacher sur la scène. Cette technique simple permet d'injecter à tout moment des nouvelles définitions d'objets à la main dans la fabrique avec la méthode &lt;strong&gt;addObjectDefinition()&lt;/strong&gt;.&lt;/p&gt;


&lt;h3&gt;3-4 - Inspection des propriétés et méthodes de la classe ObjectFactory, base de la fabrique IOC (interface IObjectFactory)&lt;/h3&gt;


&lt;p&gt;Voici l'ensemble des méthodes et propriétés définies par l'interface &lt;strong&gt;IObjectFactory&lt;/strong&gt; implémentée par la classe &lt;strong&gt;EdenObjectFactory&lt;/strong&gt; (hérite de la classe &lt;strong&gt;ObjectFactory&lt;/strong&gt;). La classe ObjectFactory reste de plus bas niveau et permet à ceux qui le désirent de garder le moteur &lt;strong&gt;IoC&lt;/strong&gt; de &lt;strong&gt;AndromedAS&lt;/strong&gt; en utilisant un parseur &lt;strong&gt;XML&lt;/strong&gt; ou autre pour remplir la fabrique.&lt;/p&gt;


&lt;p&gt;&lt;a href=&quot;http://www.ekameleon.net/blog/public/images/tutoriaux/IoC/ObjectFactory_properties.jpg&quot;&gt;&lt;img src=&quot;http://www.ekameleon.net/blog/public/images/tutoriaux/IoC/ObjectFactory_properties.jpg&quot; alt=&quot;ObjectFactory properties&quot; /&gt;&lt;/a&gt;&lt;/p&gt;


&lt;h3&gt;3-5 - Inspection des propriétés et méthodes de la classe ECMAObjectFactory.&lt;/h3&gt;


&lt;p&gt;Voici l'ensemble des méthodes statiques définies dans la classe &lt;strong&gt;EdenObjectFactory&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;&lt;img src=&quot;http://www.ekameleon.net/blog/public/images/tutoriaux/IoC/ECMAObjectFactory_properties.jpg&quot; alt=&quot;ECMAObjectFactory properties&quot; /&gt;&lt;/p&gt;


&lt;p&gt;Cette classe contient le moteur d'initialisation de la fabrique. Le conteneur interprète une collection de type &lt;strong&gt;Array&lt;/strong&gt; contenant des &lt;strong&gt;objets génériques&lt;/strong&gt; simples (format &lt;strong&gt;ECMAScript&lt;/strong&gt;) et peut ainsi créer ses propres &lt;strong&gt;définitions d'objets&lt;/strong&gt; de type &lt;strong&gt;ObjectDefinition&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;La classe &lt;strong&gt;ECMAObjectFactory&lt;/strong&gt; contient aussi un ensemble de méthodes statiques (voir tableau ci-dessus) qui permettent de créer plusieurs instances globales dans une application (voir &lt;strong&gt;chapitre A.3-5&lt;/strong&gt;).&lt;/p&gt;


&lt;h3&gt;3-6 - Plusieurs fabriques IoC dans vos application.&lt;/h3&gt;


&lt;p&gt;La classe &lt;strong&gt;EdenObjectFactory&lt;/strong&gt; peut être instanciée tout simplement avec le mot clé &lt;strong&gt;new&lt;/strong&gt; mais si nous regardons de plus prêt nous pouvons oberver dans sa signature qu'elle implémente l'interface &lt;a href=&quot;http://www.ekameleon.net/vegas/docs/vegas/core/Identifiable.html&quot;&gt;vegas.core.Identifiable&lt;/a&gt;. Cette interface définie l'existance d'un attribut &quot;&lt;strong&gt;id&lt;/strong&gt;&quot; qu'il est possible de définir sur toutes les instances de la classe.&lt;/p&gt;


&lt;p&gt;De façon générale, ce petit attribut peut être pratique mais il trouve tout son intérêt si l'on utilise la fonctionnalité &quot;&lt;strong&gt;multi-singleton&lt;/strong&gt;&quot; de la classe. Cette notion permet de définir plusieurs références globales uniques dans l'application de type &lt;strong&gt;ECMAObjectFactory&lt;/strong&gt;. On peut ainsi utiliser dans une même application plusieurs modules définis par des fabriques &lt;strong&gt;IoC&lt;/strong&gt; totalement indépendantes.&lt;/p&gt;


&lt;p&gt;La classe &lt;strong&gt;EdenObjectFactory&lt;/strong&gt; contient donc une méthode statique &lt;strong&gt;getInstance( id:String=null )&lt;/strong&gt; qui permet de créer et renvoyer des références uniques de la classe en fonction d'un identifiant spécifique et lui aussi unique. La classe contient d'autres méthodes statiques permettant de supprimer complètement un singleton de la classe en mémoire mais aussi de vérifier si pour un identifiant donné, un &lt;strong&gt;singleton&lt;/strong&gt; de la classe existe.&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Exemple :&lt;/strong&gt;&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; andromeda.ioc.factory.ECMAObjectFactory;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; factory&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;ECMAObjectFactory;
&amp;nbsp;
factory = ECMAObjectFactory.getInstance&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;ECMAObjectFactory.getInstance() : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; factory &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot; with the default id : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; factory.id &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
factory = ECMAObjectFactory.getInstance&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;factory_one&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;ECMAObjectFactory.getInstance('factory_one')      : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; factory &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot; with the default id : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; factory.id &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;ECMAObjectFactory.containsInstance('factory_one') : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; ECMAObjectFactory.containsInstance&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;factory_one&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;ECMAObjectFactory.removeInstance('factory_one')   : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; ECMAObjectFactory.removeInstance&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;factory_one&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;ECMAObjectFactory.containsInstance('factory_one') : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; ECMAObjectFactory.containsInstance&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;factory_one&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;&lt;/pre&gt;



&lt;h2&gt;4 - La classe asgard.net.ECMAObjectLoader.&lt;/h2&gt;


&lt;h3&gt;4-1 - Définition et exemple de base.&lt;/h3&gt;


&lt;p&gt;La classe &lt;strong&gt;ECMAObjectLoader&lt;/strong&gt; est une classe un peu particulière car elle ne se trouve pas directement dans l'extension &lt;strong&gt;AndromedAS&lt;/strong&gt;. En effet pour utiliser cette classe il faut la cibler dans le package &lt;strong&gt;asgard.net.*&lt;/strong&gt; de l'extension &lt;strong&gt;ASGard&lt;/strong&gt; de &lt;strong&gt;VEGAS&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;Cette classe est utilisée pour charger un ou plusieurs fichiers externes qui permettront d'initialiser la fabrique &lt;strong&gt;IoC&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Exemple :&lt;/strong&gt;&lt;/p&gt;

&lt;pre class=&quot;actionscript&quot;&gt;&lt;span style=&quot;color: #0066CC;&quot;&gt;import&lt;/span&gt; asgard.&lt;span style=&quot;color: #006600;&quot;&gt;net&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;ECMAObjectLoader&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;var&lt;/span&gt; loader:ECMAObjectLoader = &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; ECMAObjectLoader&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;application.eden&amp;quot;&lt;/span&gt; , &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;context/&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
loader.&lt;span style=&quot;color: #006600;&quot;&gt;run&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ;&lt;/pre&gt;


&lt;p&gt;Toute instance de la classe &lt;strong&gt;ECMAObjectLoader&lt;/strong&gt; contient par défaut une référence vers la référence &lt;strong&gt;singleton&lt;/strong&gt; définie par défaut de la classe &lt;strong&gt;ECMAObjectFactory&lt;/strong&gt; mais il est possible de modifier cette référence avec tout autre objet du même type.&lt;/p&gt;


&lt;p&gt;La classe &lt;strong&gt;ECMAObjectLoader&lt;/strong&gt; utilise également par défaut un chargeur de données externe basé sur un parsing &lt;strong&gt;eden&lt;/strong&gt; avec la classe &lt;strong&gt;asgard.net.EdenLoader&lt;/strong&gt;. Vous pouvez en cas de besoin modifier ce chargeur pas un autre. Par exemple dans le cas d'un chargement de données via un fichier texte au format &lt;strong&gt;JSON&lt;/strong&gt; vous pouvez utiliser la classe &lt;strong&gt;asgard.net.JSONLoader&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;Vous pouvez créer vos propres &lt;strong&gt;chargeurs/parseurs/désérialisations&lt;/strong&gt; de données avec un format &lt;strong&gt;XML&lt;/strong&gt; ou autre en créant votre propre classe de chargement qui héritera de la classe &lt;strong&gt;asgard.net.ParserLoader&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;La classe &lt;strong&gt;ECMAObjectLoader&lt;/strong&gt; est un objet basé sur le modèle de commandes et d'actions de &lt;strong&gt;AndromedAS&lt;/strong&gt;, elle implémente l'interface &lt;strong&gt;andromeda.process.IAction&lt;/strong&gt;. Une fois les fichiers de configurations chargées la classe &lt;strong&gt;ECMAObjectLoader &lt;/strong&gt; remplit le conteneur d'&lt;strong&gt;Inversion de Contrôle&lt;/strong&gt;.&lt;/p&gt;


&lt;h3&gt;4-2 - Exemple d'utilisation&amp;nbsp;: &quot;hello world&quot;.&lt;/h3&gt;


&lt;p&gt;Illustrons l'utilisation de la fabrique IoC &quot;&lt;strong&gt;ECMAObjectFactory&lt;/strong&gt;&quot; avec son chargeur de configurations externes &quot;&lt;strong&gt;ECMAObjectLoader&lt;/strong&gt;&quot; avec un exemple basique, en créant dynamiquement un champ de texte dans une animation au format &lt;strong&gt;SWF&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;Tout d'abord, nous allons créer un fichier au format texte (&lt;strong&gt;UTF8&lt;/strong&gt;) externe de configuration avec la chaîne de caractères (format &lt;strong&gt;eden&lt;/strong&gt;) suivante&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript&quot;&gt;objects =
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
        id        : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;my_format&amp;quot;&lt;/span&gt; ,
        &lt;span style=&quot;color: #0066CC;&quot;&gt;type&lt;/span&gt;      : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;flash.text.TextFormat&amp;quot;&lt;/span&gt; ,
        &lt;span style=&quot;color: #0066CC;&quot;&gt;arguments&lt;/span&gt; : &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; value:&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;arial&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; , &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; value:&lt;span style=&quot;color: #cc66cc;&quot;&gt;24&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; , &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; value:0xFEF292 &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; , &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; value:&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;true&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
    ,
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
        id         : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;my_field&amp;quot;&lt;/span&gt; ,
        &lt;span style=&quot;color: #0066CC;&quot;&gt;type&lt;/span&gt;       : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;flash.text.TextField&amp;quot;&lt;/span&gt;  ,
        properties :
        &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;
            &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #0066CC;&quot;&gt;name&lt;/span&gt; : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;autoSize&amp;quot;&lt;/span&gt;          , value  : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;left&amp;quot;&lt;/span&gt;            &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; ,
            &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #0066CC;&quot;&gt;name&lt;/span&gt; : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;defaultTextFormat&amp;quot;&lt;/span&gt; , ref    : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;my_format&amp;quot;&lt;/span&gt;       &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; ,
            &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #0066CC;&quot;&gt;name&lt;/span&gt; : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;text&amp;quot;&lt;/span&gt;              , value  : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;HELLO WORLD&amp;quot;&lt;/span&gt;     &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; ,
            &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #0066CC;&quot;&gt;name&lt;/span&gt; : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;x&amp;quot;&lt;/span&gt;                 , value  : &lt;span style=&quot;color: #cc66cc;&quot;&gt;10&lt;/span&gt;                &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; ,
            &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #0066CC;&quot;&gt;name&lt;/span&gt; : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;y&amp;quot;&lt;/span&gt;                 , value  : &lt;span style=&quot;color: #cc66cc;&quot;&gt;10&lt;/span&gt;                &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
        &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
    ,
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
        id               : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;root&amp;quot;&lt;/span&gt; ,
        &lt;span style=&quot;color: #0066CC;&quot;&gt;type&lt;/span&gt;             : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;flash.display.MovieClip&amp;quot;&lt;/span&gt;  ,
        factoryReference : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;#root&amp;quot;&lt;/span&gt; ,
        singleton        : &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;true&lt;/span&gt; ,
        properties       :
        &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;
            &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #0066CC;&quot;&gt;name&lt;/span&gt; : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;addChild&amp;quot;&lt;/span&gt; , &lt;span style=&quot;color: #0066CC;&quot;&gt;arguments&lt;/span&gt;  : &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; ref:&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;my_field&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
        &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; ;&lt;/pre&gt;


&lt;p&gt;Le fichier de configuration externe permet de définir 3 définitions d'objet&amp;nbsp;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&quot;my_format&quot;&lt;/strong&gt;&amp;nbsp;: cette définition permet de créer des instances de types &lt;strong&gt;flash.text.TextFormat&lt;/strong&gt;, cette définition injecte des dépendances via la fonction constructeur de la classe pour initialiser l'objet.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&quot;my_field&quot;&lt;/strong&gt;&amp;nbsp;: cette définition permet de créer des champs de texte dynamiques de type &lt;strong&gt;flash.text.TextField&lt;/strong&gt; avec une initialisation de certains de ces attributs avec des injections de dépendance via l'attribut &lt;strong&gt;&quot;properties&quot;&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&quot;root&quot;&lt;/strong&gt;&amp;nbsp;: cette définition permet de créer une référence &lt;strong&gt;singleton&lt;/strong&gt; qui cible la scène principale de l'application définie dans la configuration de la fabrique &lt;strong&gt;IoC&lt;/strong&gt; (voir code ci-dessous) et d'attacher dessus le champ de texte dynamique &lt;strong&gt;&quot;my_field&quot;&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Remarque&lt;/strong&gt;&amp;nbsp;: le nom d'extension &lt;strong&gt;&quot;.eden&quot;&lt;/strong&gt; n'est pas obligatoire, il suffit que le fichier externe contienne juste du texte au format eden pour que le chargeur fasse correctement son travail. Il est donc possible d'utiliser des fichiers portant l'extension &lt;strong&gt;.txt&lt;/strong&gt; par exemple, même si il est tout de même plus simple d'utiliser une extension différente pour distinguer correctement vos fichiers de configuration au format &lt;strong&gt;eden&lt;/strong&gt; par rapport à d'autres.&lt;/p&gt;


&lt;p&gt;Il ne reste plus qu'à charger ce fichier de configuration et de remplir un conteneur IoC avec la classe &lt;strong&gt;ECMAObjectLoader&lt;/strong&gt;&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; andromeda.events.ActionEvent;
&amp;nbsp;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; asgard.net.ECMAObjectLoader ;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; debug&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Function&lt;/span&gt; = &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; e&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Event&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
     &lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; e &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;loader&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;ECMAObjectLoader = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; ECMAObjectLoader&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;hello_world.eden&amp;quot;&lt;/span&gt; , &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;context/&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;loader&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;root&lt;/span&gt; = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;this&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// to use the &amp;quot;#root&amp;quot; expression in the 'ref' attribute.&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;loader&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;addEventListener&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; ActionEvent.START  , debug &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&lt;span style=&quot;color: #004993;&quot;&gt;loader&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;addEventListener&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; ActionEvent.FINISH , debug &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;loader&lt;/span&gt;.run&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;&lt;/pre&gt;


&lt;p&gt;L'exemple ci-dessus illustre&amp;nbsp;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;L'utilisation de plusieurs définitions d'objets chargées dans un fichier externe.&lt;/li&gt;
&lt;li&gt;La notion de dépendance entre une définition d'objet et une autre&lt;/li&gt;
&lt;li&gt;La notion de dépendance avec une référence &quot;magique&quot; (#root) qui permet de cibler la référence d'un objet spécial défini dans l'application.&lt;/li&gt;
&lt;li&gt;La méthode pour créer un objet visuel (ici un champ de texte) directement avec la fabrique sans appeler sa définition dans le code ActionScript.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Cet exemple très basique dévoile quelques fonctionnalités disponibles dans la moteur &lt;strong&gt;IoC&lt;/strong&gt; de &lt;strong&gt;AndromedAS&lt;/strong&gt;. Nous chargeons un fichier texte encodé en &lt;strong&gt;UTF8&lt;/strong&gt; &lt;strong&gt;&quot;hello_world.eden&quot;&lt;/strong&gt; défini dans un répertoire &lt;strong&gt;&quot;context/&quot;&lt;/strong&gt; situé au même niveau que le &lt;strong&gt;swf&lt;/strong&gt; de l'application de test.&lt;/p&gt;


&lt;p&gt;Le constructeur de la classe &lt;strong&gt;ECMAObjectLoader&lt;/strong&gt; permet de définir le nom complet du fichier de configuration que l'on souhaite charger mais aussi le répertoire principal dans lequel il se trouve. Si aucun paramètre n'est défini dans la fonction constructeur de la classe alors le chargeur essaie de charger un fichier &lt;strong&gt;&quot;application.eden&quot;&lt;/strong&gt; situé au même niveau que le &lt;strong&gt;swf&lt;/strong&gt; de l'application.&lt;/p&gt;


&lt;p&gt;Ce fichier texte est ensuite parsé par le moteur de désérialization &lt;strong&gt;eden&lt;/strong&gt; puis injecté automatiquement dans le fabrique IoC principale de l'application définie dans la classe &lt;strong&gt;ECMAObjectLoader&lt;/strong&gt; par défaut&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; andromeda.ioc.factory.ECMAObjectFactory ;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; andromeda.ioc.factory.IObjectFactory ;
&amp;nbsp;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; asgard.net.ECMAObjectLoader ;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;loader&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;ECMAObjectLoader = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; ECMAObjectLoader&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; factory&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;IObjectFactory = &lt;span style=&quot;color: #004993;&quot;&gt;loader&lt;/span&gt;.factory ;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; factory == ECMAObjectFactory.getInstance&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// true&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Il est bien entendu possible de modifier cette référence par une autre de type &lt;strong&gt;IObjectFactory&lt;/strong&gt; à tout moment dans l'application mais il est tout de même préférable de tenter ce genre d'opérations en maitrisant parfaitement le moteur &lt;strong&gt;IoC&lt;/strong&gt; de &lt;strong&gt;AndromedAS&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;La classe &lt;strong&gt;ECMAObjectLoader&lt;/strong&gt; possède un modèle évènementiel simple basée sur le moteur d'&lt;strong&gt;Action et process&lt;/strong&gt;  de &lt;strong&gt;AndromedAS&lt;/strong&gt; qui lui permet de notifier l'utilisateur du début et de la fin de l'initialisation du conteneur léger en passant par un &quot;&lt;strong&gt;helper&lt;/strong&gt;&quot; de type &lt;strong&gt;ECMAObjectLoader&lt;/strong&gt;.&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; andromeda.events.ActionEvent;
&amp;nbsp;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; asgard.net.ECMAObjectLoader ;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; debug&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Function&lt;/span&gt; = &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; e&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Event&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quo