<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Yanik Lupien</title>
	<atom:link href="http://yanik-lupien.com/feed" rel="self" type="application/rss+xml" />
	<link>http://yanik-lupien.com</link>
	<description>Programmeur PHP senior</description>
	<lastBuildDate>Wed, 22 Feb 2012 03:01:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Rapport de densité Google Map</title>
		<link>http://yanik-lupien.com/javascript/rapport-de-densite-google-map</link>
		<comments>http://yanik-lupien.com/javascript/rapport-de-densite-google-map#comments</comments>
		<pubDate>Fri, 17 Feb 2012 05:17:53 +0000</pubDate>
		<dc:creator>Yanik Lupien</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Google Map]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://yanik-lupien.com/?p=839</guid>
		<description><![CDATA[Nouvelle réalisation JavaScript. L’entreprise Meb Web fait des concours Facebook. Leur besoin était d’être en mesure d’offrir à leur client un rapport géographique qui affiche la densité des inscriptions.]]></description>
			<content:encoded><![CDATA[<p>Nouvelle réalisation JavaScript. L’entreprise <a href="http://www.mebweb.ca/">Meb Web</a> fait des concours Facebook. Leur besoin était d’être en mesure d’offrir à leur client un rapport géographique qui affiche la densité des inscriptions. </p>
<p><img src="http://yanik-lupien.com/wp-content/uploads/2012/02/map-report-550x400.png" alt="Rapport Google" title="map-report" width="550" height="400" class="alignnone size-medium wp-image-838" /></p>
]]></content:encoded>
			<wfw:commentRss>http://yanik-lupien.com/javascript/rapport-de-densite-google-map/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lite Brite en Javascript / Canvas</title>
		<link>http://yanik-lupien.com/realisations/preuve-de-concept/lite-brite-en-javascript-canvas</link>
		<comments>http://yanik-lupien.com/realisations/preuve-de-concept/lite-brite-en-javascript-canvas#comments</comments>
		<pubDate>Sat, 04 Feb 2012 18:14:39 +0000</pubDate>
		<dc:creator>Yanik Lupien</dc:creator>
				<category><![CDATA[Preuve de concept]]></category>

		<guid isPermaLink="false">http://yanik-lupien.com/?p=820</guid>
		<description><![CDATA[Voici l&#8217;histoire de la naissance d&#8217;un petit projet HTML5 / Javascript. Un soir où je soupais avec ma chère amie Marie-Eve de Meb Web. Nous avons discuté du projet Noël en Lumière qu&#8217;Absolunet a fait pour la Tablée des Chefs, un organisme qui vient en aide aux familles dans le besoin. Je lui dis comme [...]]]></description>
			<content:encoded><![CDATA[<p>Voici l&#8217;histoire de la naissance d&#8217;un petit projet HTML5 / Javascript.</p>
<p>Un soir où je soupais avec ma chère amie Marie-Eve de <a href="http://www.meb-web.ca/">Meb Web</a>. Nous avons discuté du projet <a href="http://www.noelenlumieres.com/">Noël en Lumière</a> qu&#8217;<a href="http://www.absolunet.com/">Absolunet</a> a fait pour la <a href="http://www.tableedeschefs.org/">Tablée des Chefs</a>, un organisme qui vient en aide aux familles dans le besoin.</p>
<p>Je lui dis comme ça sans trop penser&#8230;</p>
<blockquote><p>L&#8217;application en soi est très simple à faire&#8230; Je suis sûre qu&#8217;en une soirée je pourrais faire une version basique utilisable qui ressemble à ce qu&#8217;Absolunet a fait.</p></blockquote>
<p>Je venais de me lancer un petit défi personnel.</p>
<p><span id="more-820"></span>Arrivée à la maison ce soir-là, je décidais de faire un mini Lite Brite en HTML5 / Javascript pour voir si j&#8217;étais en mesure d&#8217;accomplir ce que j&#8217;avais dit.</p>
<p>2-3 heures plus tard, j&#8217;envoyais un démo à Marie. Bien sûr, c&#8217;était plus une preuve de concept, mais il était possible de dessiner avec différentes couleurs sur une surface.</p>
<p>Le lendemain, j&#8217;ajoutais la possibilité de sauvegarder plus celle de se connecter avec son compte Facebook dans le but d&#8217;associer les dessins faits par l&#8217;utilisateur à un espace différent de sauvegarde.</p>
<p><img class="alignnone size-medium wp-image-830" title="LiteBrite" src="http://yanik-lupien.com/wp-content/uploads/2012/02/LiteBrite-550x465.png" alt="" width="550" height="465" /></p>
<p>Voici ce que donne la version actuel de l&#8217;application <a href="http://yanik-lupien.com/demos/litebritefb/">HTML5 Lite Brite</a>.</p>
<p>Éventuellement j&#8217;aimerais ajouter la possibilité de partager les dessins faits par l&#8217;utilisateur sur Facebook. Pour faire cette fonctionnalité, je vais probablement utiliser la librairie GD de PHP pour produire une image GIF ou PNG similaire au dessin fait par l&#8217;utilisateur.</p>
]]></content:encoded>
			<wfw:commentRss>http://yanik-lupien.com/realisations/preuve-de-concept/lite-brite-en-javascript-canvas/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Les associations mentales tuent la productivité</title>
		<link>http://yanik-lupien.com/articles-php/les-associations-mental-tue-la-productivite</link>
		<comments>http://yanik-lupien.com/articles-php/les-associations-mental-tue-la-productivite#comments</comments>
		<pubDate>Sun, 01 Jan 2012 00:37:29 +0000</pubDate>
		<dc:creator>Yanik Lupien</dc:creator>
				<category><![CDATA[Articles PHP]]></category>
		<category><![CDATA[Espace de nom]]></category>
		<category><![CDATA[Nom de classes]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Productivité]]></category>
		<category><![CDATA[Professionnel]]></category>

		<guid isPermaLink="false">http://yanik-lupien.com/?p=715</guid>
		<description><![CDATA[Lorsque vous regardez un code, et que celui-ci n&#8217;est pas explicite ou utilise des noms non significatifs, vous devez retenir la signification de certain élément dans le but de comprendre la suite. Ou lorsque vous devez constamment vous remettre en contexte pour comprendre. Par exemple lorsque vous lisez $object = new User(); vous devez vous [...]]]></description>
			<content:encoded><![CDATA[<p>Lorsque vous regardez un code, et que celui-ci n&#8217;est pas explicite ou utilise des noms non significatifs, vous devez retenir la signification de certain élément dans le but de comprendre la suite. Ou lorsque vous devez constamment vous remettre en contexte pour comprendre. </p>
<p>Par exemple lorsque vous lisez <strong>$object = new User();</strong> vous devez vous créer une association mentale (objet signifie User) et la retenir pour être en mesure de comprendre la suite du code. </p>
<p>Si vous avez eu a la place <strong>$user = new User();</strong>, vous n&#8217;avez pas à vous référer à une autre ligne a un autre endroit dans le fichier ou retourner dans votre mémoire pour vous souvenir de l&#8217;association mentale. La variable est explicite et dit exactement ce qu&#8217;il y a l&#8217;intérieur. Résultat la compréhension du code s&#8217;en retrouve amélioré et facilité.</p>
<p>Une instance de la class User est déjà un concept abstrait puisqu&#8217;il n&#8217;est pas possible de savoir si c&#8217;est le User Roger ou Alphone.</p>
<p>Si vous avez une seule association, vous n&#8217;aurez probablement pas de problème à lire et comprendre. Imaginez, si vous devez faire référence à plusieurs associations, vous risquez d&#8217;avoir beaucoup de difficulté à lire et comprendre le code.<br />
<span id="more-715"></span></p>
<h3>Les associations mentales avec les méthodes et fonctions</h3>
<p>Lorsque vous définissez une fonction ou méthode qui comporte un nombre d&#8217;arguments très élevé plus de 2 ou 3, il devient difficile de se souvenir de la signification de ceux-ci sans avoir à se référer à sa définition lors de son utilisation.</p>
<p><strong>CreateUser.php</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$userFactory</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">create</span><span style="color: #009900;">&#40;</span>
   <span style="color: #0000ff;">'Yanik'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Lupien'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Programmeur PHP'</span><span style="color: #339933;">,</span> 
   <span style="color: #cc66cc;">35</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'2010-10-12'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'08:33'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$userRepo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">persist</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Regardez, cet appel de méthode, et essayer de deviner la signification du 7e ou 8e argument. </p>
<p>Êtes-vous en mesure de savoir ? </p>
<p>Probablement pas. </p>
<p>Voici quelque chemin difficile possible pour y arriver.</p>
<ul>
<li>lire la définition de la méthode en allant consulter le fichier où se trouve la définition de la classe. </li>
<li>Si vous avez de la chance que le programmeur ait correctement documenté la méthode pour que l&#8217;IDE soit en mesure de vous donner une aide contextuelle. Par exemple avec Eclipse vous pouvez avoir un accès rapide à la définition en gardant CRTL enfoncé et par un clique sur le nom de la méthode &laquo;&nbsp;create&nbsp;&raquo;.</li>
</ul>
<p>Maintenant que vous avez trouvé le bon fichier et la bonne méthode. Vous avez maintenant la définition devant vous.</p>
<p><strong>UserFactory.php</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> UserFactory <span style="color: #009900;">&#123;</span>
<span style="color: #339933;">...</span>
<span style="color: #009933; font-style: italic;">/**
 * Create a new user base on this exhaustive list of arguments.
 * 
 * @param string $firstName 
 * @param string $lastName
 * @param string $description 
 * @param string $age 
 * @param string $createdDate 
 * @param string $createdTime 
 * @param boolean $active User account active or not
 * @param integer $countryId Country id where the user live
 * @param integer $stateId (Optional) State id where the user live
 * @param array $options (Optional) Some options. 
 * @return User
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> create<span style="color: #009900;">&#40;</span>
    <span style="color: #000088;">$firstName</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lastName</span><span style="color: #339933;">,</span> <span style="color: #000088;">$description</span><span style="color: #339933;">,</span> <span style="color: #000088;">$age</span><span style="color: #339933;">,</span> 
    <span style="color: #000088;">$createdDate</span><span style="color: #339933;">,</span> <span style="color: #000088;">$createdTime</span><span style="color: #339933;">,</span> 
    <span style="color: #000088;">$active</span><span style="color: #339933;">,</span> <span style="color: #000088;">$countryId</span><span style="color: #339933;">,</span> <span style="color: #000088;">$stateId</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
    <span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> User<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setFirstName</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$firstName</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setLastName</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$lastName</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setDescription</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$description</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setAge</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$age</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setCreatedDate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$createdDate</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setCreatedTime</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$createdTime</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setActive</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$active</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setCountryId</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$countryId</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setStateId</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$stateId</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setOptions</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$user</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">...</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Vous regardez la définition. Pour vous simplifier la vie, vous essayez de lire à partir du dernier argument. Non ça ne fonctionne pas très bien, car ceux si sont optionnel donc vous mettez donc à compter les arguments à partir du début. Finalement, êtes en mesure de savoir que l&#8217;argument #5 est en fait le statues actif ou non et que le 6e est le ID du pays. </p>
<h4>Les problématiques</h4>
<ul>
<li>A la lecture du code qui utilise cette méthode il est très difficile de savoir au premier coup d&#8217;oeil quel sont les différents arguments de la function.</li>
<li>Il y a aussi une duplication de la documentation de chaque propriété de la classe User. Toutes les propriétés se retrouvent redéfinies et documentées une 2e fois dans la méthode <strong>create</strong>. Nécessite une double maintenance.</li>
<li>Et finalement vous avez besoin de vous souvenir par association mentale que l&#8217;argument 3 est la description, le 4 est l&#8217;age, le 5e est date, le 6e est heure et le 7e est le statues actif ou non. </li>
</ul>
<h4>Solutions</h4>
<p><strong>Réutilisez votre code</strong>, ici c&#8217;est la définition de la classe <strong>User</strong> qui peut être réutilisable. Plutôt que d&#8217;avoir une liste exhaustive d&#8217;arguments, utilisez l&#8217;objet lui-même.</p>
<p><strong>CreateUser.php</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$userFactory</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">create</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setId</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getNewId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setFirstName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Yanik'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setLastName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Lupien'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setDescription</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Programmeur PHP'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setAge</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">99</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setCreationDate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'2010-10-12'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setCreationTime</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'08:33'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setActive</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setCountryId</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$userRepo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">persist</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Remarquez dans l&#8217;exemple précédent, pour comprendre chaque argument, vous n&#8217;avez plus à aller consulter la classe UserRepository. Vous n&#8217;avez plus non plus à compter ou vous souvenir de l&#8217;ordre. L&#8217;association est explicite. Le code se retrouve éclairci et beaucoup facile à comprendre. </p>
<p><strong>UserFactory.php</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> UserFactory <span style="color: #009900;">&#123;</span>
<span style="color: #339933;">...</span>
<span style="color: #009933; font-style: italic;">/**
 * Create a new user.
 * 
 * @return User
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> create<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
    <span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> User<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setId</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getNewId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$user</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">...</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>De plus, la classe <strong>UserFactory</strong> ne se retrouve plus avec un double de la définition de User.<br />
Vous réduisez le couplage entre les 2 classes UserRepository et le User ce qui rend la maintenance beaucoup plus facile.</p>
<p>Il reste une dernière amélioration, et elle au niveau du setCountry. Je pourrais aussi parler au sujet setOptions qui utilise un array mais je crois que je vais faire un article complet sur le sujet.</p>
<p><strong>CreateUser.php</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>8
9
10
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">...</span>
<span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setCountryId</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">...</span></pre></td></tr></table></div>

<p>Pouvez-vous me dire quelle est la signification de 3 ? </p>
<p>Probablement pas.</p>
<p>Ce qui m&#8217;apporte au sujet suivant. </p>
<h3>Association mentale numérique</h3>
<p><strong>CreateUser.php</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>8
9
10
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">...</span>
<span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setCountryId</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">...</span></pre></td></tr></table></div>

<p>Le programmeur qui a bâti ce script sait probablement la signification de ce nombre. Par contre à nos yeux celui-ci ne signifie pas grand-chose. C&#8217;est peu&#8217;être&#8230; Canada, É.-U., France, Chine&#8230; </p>
<p>Une fois de plus nous devons chercher la source et consulter la signification de ce nombre. </p>
<p>Puisque le nombre de pays n&#8217;est pas si élevé et que celui-ci est généralement fixe, il nous est donc possible de définir des constantes pour rendre le code un peu plus explicite.</p>
<p><strong>Country.php</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Country <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">const</span> USA <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">const</span> CANADA <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">const</span> CHINA <span style="color: #339933;">=</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">const</span> JAPAN <span style="color: #339933;">=</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">;</span>
    <span style="color: #339933;">...</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Ce qui donne une lecture beaucoup plus explicite que la précédente.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>8
9
10
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">...</span>
<span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setCountryId</span><span style="color: #009900;">&#40;</span>Country<span style="color: #339933;">::</span><span style="color: #004000;">CHINA</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">...</span></pre></td></tr></table></div>

<p>Une fois de plus nous avons amélioré l&#8217;expérience de lecture pour nos collègues programmeurs.</p>
<h3>Name space &#038; Association mentale</h3>
<p>Avec l&#8217;arrivé des names space dans PHP 5, plusieurs se sont lance dans leur utilisation. Encore une fois si nous le lecteur somme obliger de faire des associations mental pour comprendre le code, il est très probable que leur utilisation soit erronée.</p>
<p>Voici un exemple où un programmeur avait à la base une bonne intention, celle d&#8217;uniformité la structure de chaque entité de l&#8217;entreprise. Puisque chaque entité <strong>User</strong>, <strong>Site</strong>, <strong>Customer</strong>, &#8230; avait plusieurs classes telles que la classe <strong>Entite</strong>, l&#8217;interface  <strong>Repository</strong>, la classe d&#8217;<strong>Exception</strong>, la classe <strong>Collection</strong>, &#8230; celui-ci s&#8217;est dit je vais créer un espace de nom propre a chaque entité.</p>
<p><strong>Voici la structure des namespace et ses fichiers</strong></p>
<pre>
namespace MyCompany\User;
Libs\MyCompany\User\Collection.php
Libs\MyCompany\User\Entity.php
Libs\MyCompany\User\Exception.php
Libs\MyCompany\User\Repository.php
...
namespace MyCompany\Site;
Libs\MyCompany\Site\Collection.php
Libs\MyCompany\Site\Entity.php
Libs\MyCompany\Site\Exception.php
Libs\MyCompany\Site\Repository.php
...
namespace MyCompany\Customer;
Libs\MyCompany\Customer\Collection.php
Libs\MyCompany\Customer\Entity.php
Libs\MyCompany\Customer\Exception.php
Libs\MyCompany\Customer\Repository.php
</pre>
<p>À première vue l&#8217;idée semble bonne. Tous les fichiers sont uniformisés. C&#8217;est bien organise et en ordre. Il n&#8217;y a pas de redondance dans le les noms. C&#8217;est propre et la structure de fichier est claire. </p>
<p>Maintenant voici la définition de la classe MyCompany\User\Entity et MyCompany\User\Repository</p>
<p><strong>Lib\MyCompany\User\Entity.php</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>8
9
10
11
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">namespace</span> MyCompany\User<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">class</span> Entity <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><strong>Lib\MyCompany\User\Repository.php</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">namespace</span> MyCompany\User<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">interface</span> Repository <span style="color: #009900;">&#123;</span>
    <span style="color: #009933; font-style: italic;">/**
     * Find entity by unique id
     * @return Entity
     */</span>
    <span style="color: #000000; font-weight: bold;">function</span> findById<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Find a entity by name
     * @return Collection
     */</span>
    <span style="color: #000000; font-weight: bold;">function</span> findById<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Save an entity to repository
     * @param Entity $entity Entity to save in repository
     * @return void
     */</span>
    <span style="color: #000000; font-weight: bold;">function</span> save<span style="color: #009900;">&#40;</span>Entity <span style="color: #000088;">$entity</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>À première vue les classes semblent bien organise. </p>
<h4>Voici les problématiques</h4>
<ul>
<li>Pour comprendre le fichier il est toujours nécessaire de faire référence a une association mentale et où de se remettre en contexte.</li>
<li>A la lecture du code de ces classes, il est facile de penser que ce sont des définitions abstraites puisque les noms <strong>Entite</strong>, <strong>Repository</strong>, &#8230; font référence à des concepts très abstraits que la spécialisation qui est décrit par ces fichiers. Il faut se référer à l&#8217;espace de nom pour comprendre la signification du context de celui çi.</li>
<li>les méthodes sont aussi documentées relativement à l&#8217;espace de nom. Par exemple, la méthode findByName plutôt que de retourner un <strong>UserCollection</strong> retourne une <strong>Collection</strong> encore une fois la notion de Collection fait référence à une notion très abstraite. Alors que dans les fait cette méthode retourne une UserCollection, une instance très spécialisée.</li>
<li>comme les noms de classes et interfaces, les noms de fichiers porte le même nom que ceux-ci et font donc aussi référence à un concept abstrait non spécialisé. Si vous ouvrez 4 fichiers Entity.php dans un IDE comme Eclipse, il devient très difficile de s&#8217;orienter et de savoir dans quelle spécialisation nous sommes.</li>
</ul>
<h4>Solutions</h4>
<p>Dans le cas actuel, renommer les fichiers, les classe, les variables et les commentaires à leur spécialisation aiderait énormément la compréhension. Dans le cas actuel, il est vrai qu&#8217;il y aurait une redondance du nom dans la structure. L&#8217;avantage gagné au niveau de la lecture et compréhension du code compense largement cette petite redondance. Il y a toujours possibilité de changer la structure <img src='http://yanik-lupien.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>8
9
10
11
12
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">namespace</span> MyCompany\Customer<span style="color: #339933;">;</span>
Libs\MyCompany\Customer\CustomerCollection<span style="color: #339933;">.</span>php
Libs\MyCompany\Customer\CustomerEntity<span style="color: #339933;">.</span>php
Libs\MyCompany\Customer\CustomerException<span style="color: #339933;">.</span>php
Libs\MyCompany\Customer\CustomerRepository<span style="color: #339933;">.</span>php</pre></td></tr></table></div>

<p><strong>Lib\MyCompany\User\UserRepository.php</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">namespace</span> MyCompany\User<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">interface</span> UserRepository <span style="color: #009900;">&#123;</span>
    <span style="color: #009933; font-style: italic;">/**
     * Find UserEntity by unique id
     * @return UserEntity
     */</span>
    <span style="color: #000000; font-weight: bold;">function</span> findById<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Find a entity by name
     * @return UserCollection
     */</span>
    <span style="color: #000000; font-weight: bold;">function</span> findById<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Save an UserEntity to current repository
     * @param UserEntity $user User to save in repository
     * @return void
     */</span>
    <span style="color: #000000; font-weight: bold;">function</span> save<span style="color: #009900;">&#40;</span>UserEntity <span style="color: #000088;">$user</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h3>Conclusion</h3>
<p>Un collègue programmeur m&#8217;a envoyé une &laquo;&nbsp;Quote&nbsp;&raquo; intéressante, la voici :<br />
<em>&laquo;&nbsp;There is a cost associated to mental mapping&#8230; if you&#8217;re adding required mental mapping in your code, you are stealing from you employer&nbsp;&raquo;.</em></p>
<p>En tant que développeur professionnel nous nous devons d&#8217;écrire un code clair où il est facile de se retrouver et où il est facile de comprendre l&#8217;objectif de celui-ci. Un code clair est explicite, prévisible et surtout facile à lire et comprendre sans besoin d&#8217;utiliser d&#8217;associations mentales.</p>
<h4>Références</h4>
<p><a href="http://books.google.ca/books?id=_i6bDeoCQzsC&#038;pg=PT86&#038;lpg=PT86&#038;dq=avoid+mental+mapping&#038;source=bl&#038;ots=en4PAm7b44&#038;sig=2wmSnEg045Dywh6Jc_hKldpsmdM&#038;hl=fr&#038;sa=X&#038;ei=_J__TpTHHujq0gGp6NnJAg&#038;ved=0CDAQ6AEwAQ#v=onepage&#038;q=avoid%20mental%20mapping&#038;f=false">books.google.ca / Clean Code: A Handbook of Agile Software Craftsmanship</a></p>
]]></content:encoded>
			<wfw:commentRss>http://yanik-lupien.com/articles-php/les-associations-mental-tue-la-productivite/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>7 idées pour s&#8217;améliorer en programmation PHP</title>
		<link>http://yanik-lupien.com/articles-php/7-idees-pour-sameliorer-en-programmation-php</link>
		<comments>http://yanik-lupien.com/articles-php/7-idees-pour-sameliorer-en-programmation-php#comments</comments>
		<pubDate>Tue, 09 Aug 2011 00:44:40 +0000</pubDate>
		<dc:creator>Yanik Lupien</dc:creator>
				<category><![CDATA[Articles PHP]]></category>

		<guid isPermaLink="false">http://yanik-lupien.com/?p=556</guid>
		<description><![CDATA[1.L&#8217;utilisation des constantes pour le bien de vos yeux Trop souvent les programmeurs PHP ont utilises les constantes pour différent usage tel que configuration, langage, variable globale. Une constante devrait être une valeur qui ne change pas tout au long de l&#8217;existence de l&#8217;application et non tout au long de l&#8217;exécution du script. Par exemple [...]]]></description>
			<content:encoded><![CDATA[<h3>1.L&#8217;utilisation des constantes pour le bien de vos yeux</h3>
<p>Trop souvent les programmeurs PHP ont utilises les constantes pour différent usage tel que configuration, langage, variable globale. Une constante devrait être une valeur qui ne change pas tout au long de l&#8217;existence de l&#8217;application et non tout au long de l&#8217;exécution du script.</p>
<p>Par exemple si vous avez une classe RGB vous pourriez avoir la constante RGB::RED = #FF0000 cette valeur est une valeur constante elle ne changera jamais. Ce n&#8217;est pas d&#8217;avoir une valeur qui ne change pas tout au long de l&#8217;application, mais bien une valeur qui est constante qui ne change pas.</p>
<p>L&#8217;utilité principale des constantes est de clarifier votre code, de donner un nom plus humain et facile a lire. Par exemple, vous avez surmènent déjà eu des fonctions / method telle que</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$logger</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">log</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'blabla'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span> <span style="color: #339933;">|</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Mettez-vous a la place dans les souliers du programmeur neuf qui arrive et regarde cette ligne. Au premier coup d&#8217;oeil, il est facile de voir que l&#8217;ont veut logger &laquo;&nbsp;blabla&nbsp;&raquo; mais pour le reste&#8230; Aucune idée de ce que c&#8217;est.</p>
<p>Voici des exemples d&#8217;une meilleur utilisation des constantes.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$logger</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">log</span><span style="color: #009900;">&#40;</span>
   <span style="color: #0000ff;">'blabla'</span><span style="color: #339933;">,</span>
   ILog<span style="color: #339933;">::</span><span style="color: #004000;">LEVEL_WARNING</span><span style="color: #339933;">,</span>
   ILog<span style="color: #339933;">::</span><span style="color: #004000;">OPTION_DELAYED</span> <span style="color: #339933;">|</span> ILog<span style="color: #339933;">::</span><span style="color: #004000;">OPTION_MERGE</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>De cette façon, nous ne somme pas obliger d&#8217;aller voir la définition de la méthode pour la comprendre que le 2e paramètre est le niveau sévérité du message et que le 3e sont les options. </p>
<p>Voici l&#8217;exemple du RGB.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> RGB <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">const</span> RED   <span style="color: #339933;">=</span> <span style="color: #0000ff;">'#ff0000'</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">const</span> BLUE  <span style="color: #339933;">=</span> <span style="color: #0000ff;">'#0000ff'</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">const</span> GREEN <span style="color: #339933;">=</span> <span style="color: #0000ff;">'#00ff00'</span><span style="color: #339933;">;</span>
  <span style="color: #339933;">...</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Sans constante</span>
<span style="color: #000088;">$color</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> RGB<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#ff0000'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Avec constante</span>
<span style="color: #000088;">$color</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> RGB<span style="color: #009900;">&#40;</span>RGB<span style="color: #339933;">::</span><span style="color: #004000;">RED</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><span id="more-556"></span></p>
<h3>2.Apprenez des autres langages et appliquez leurs principes</h3>
<p>En C++ il est possible de définir certaines méthodes d&#8217;une classe comment étant constante. En Java un principe similaire est la définition d&#8217;interface mutable et non mutable. Le but ici est simple, c&#8217;est d&#8217;exposer à l&#8217;utilisateur de la classe que l&#8217;appel à ces méthodes ne changera pas l&#8217;état de l&#8217;instance.</p>
<p>Si vous appelez getName() sur l&#8217;instance utilisateur il ne devrait y avoir aucune variables membre de l&#8217;instance utilisateur qui devrait changer. Cette méthode est donc constante / non mutable. Tous les getter de façon générale devraient être constant / none mutable et ne devrait pas altérer l&#8217;état de l&#8217;instance.</p>
<p>En PHP il n&#8217;est pas possible de définir une méthode constante, mais il est toujours possible d&#8217;applique le principe que lorsque vous définissez un getter vous n&#8217;altérez pas l&#8217;état de votre instance.</p>
<p>Voici un exemple d&#8217;interface non mutable et mutable.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">interface</span> IUser <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">function</span> getFirstName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">function</span> getLastName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">interface</span> IUserMutable <span style="color: #000000; font-weight: bold;">extends</span> IUser <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">function</span> setFirstName<span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">function</span> setLastName<span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h3>3.Maîtrisez l&#8217;utilisation des interfaces</h3>
<p>En C++ et Java, les interfaces ne sont pas simplement une façon de s&#8217;assurer l&#8217;existence de méthodes. C&#8217;est avant tout un contrat qui définit quelles méthodes peuvent être appelées.</p>
<p><strong>Exemple d&#8217;une definition d&#8217;interface en C++</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> IUser <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">public</span><span style="color: #339933;">:</span>
  <span style="color: #990000;">virtual</span> ~IUser<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
  <span style="color: #990000;">virtual</span> <span style="color: #000000; font-weight: bold;">const</span> string getFirstName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">const</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">virtual</span> <span style="color: #000000; font-weight: bold;">const</span> string getLastName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">const</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Dans l&#8217;exemple ci-haut c&#8217;est une définition d&#8217;interface IUser avec une méthode getFirstName constante qui retourne une chaîne constante. Au final, l&#8217;appel de cette méthode sur une instance ne devrait pas changer l&#8217;état de celle çi. De plus, il ne devrait pas non plus être possible de changer la chaîne retourne. Il serait nécessaire de faire une copie pour être en mesure de la changer. Cette démarche assurer l&#8217;intégrité de l&#8217;espace mémoire utilisé par l&#8217;instance User.</p>
<p>Un des points importants est que ces langages empêchent l&#8217;appel d&#8217;autres méthodes qui ne sont pas définies dans l&#8217;interface. </p>
<p>Si dans la définition d&#8217;une méthode, vous spécifiez que vous vous attendez a recevoir une interface IUser rien ne vous empêche, d&#8217;appeler setFirstName qui fait partie de l&#8217;interface (IUserMutable). Or le jour ou vous allez passer à cette méthode une instance qui supporte seulement l&#8217;interface IUser votre allez vous apercevoir que votre méthode en fait plus qu&#8217;elle ne semble le laisser voir.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">interface</span> IUser <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">function</span> getFirstName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">function</span>  getLastName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">interface</span> IUserMutable <span style="color: #000000; font-weight: bold;">extends</span> IUser <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">function</span> setFirstName<span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">function</span> setLastName<span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> ConstantUser implements IUser <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">function</span> getFirstName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fName</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
  <span style="color: #000000; font-weight: bold;">function</span> getLastName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">lName</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> DynamicUser implements IUserMutable <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">function</span> getFirstName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fName</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
  <span style="color: #000000; font-weight: bold;">function</span> getLastName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">lName</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Ici la fonction expose a l'utilisateur qu'elle a besoin d'un IUser</span>
<span style="color: #666666; font-style: italic;">// alors qu'en réalité elle devrait exposer qu'elle a besoin d'un IUserMutable</span>
<span style="color: #000000; font-weight: bold;">function</span> doMore<span style="color: #009900;">&#40;</span>IUser <span style="color: #000088;">$user</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// cette méthode fait partie de l'interface IUser</span>
  <span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getFirstName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
  <span style="color: #666666; font-style: italic;">// Cette methode ne fait pas partie de l'interface IUser</span>
  <span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setFirstName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Yanik'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$dUser</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DynamicUser<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
doMore<span style="color: #009900;">&#40;</span><span style="color: #000088;">$dUser</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// OK</span>
&nbsp;
<span style="color: #000088;">$cUser</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ConstantUser<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
doMore<span style="color: #009900;">&#40;</span><span style="color: #000088;">$cUser</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// CRASH</span></pre></td></tr></table></div>

<p>En C++ ou Java il serait absolument nécessaire de caster le pointer à l&#8217;interface voulue.<br />
<strong>Exemple de casting C++</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="cplusplus" style="font-family:monospace;">void functionName(IUser * user) {
  IUserMutable * userMutable = dynamic_cast&lt;IUserMutable *&gt;(user);
  if (userMutable != null) {
    userMutable-&gt;setFirstName('Yanik');
  }
}</pre></td></tr></table></div>

<p><strong>Exemple de casting Java</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">void</span> <span style="color: #000000; font-weight: bold;">public</span> function functionName<span style="color: #009900;">&#40;</span>IUser user<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  IUserMutable userMutable <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>IUserMutable<span style="color: #009900;">&#41;</span> user<span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>userMutable <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    userMutable.<span style="color: #006633;">setFirstName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Yanik'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><strong>Exemple de faux casting PHP</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> functionName<span style="color: #009900;">&#40;</span>IUser <span style="color: #000088;">$user</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$userMutable</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// Faux casting ;-) </span>
  <span style="color: #666666; font-style: italic;">// Le but est simplement de rendre le code plus clair sur l'intention</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span> instanceof IUserMutable<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$userMutable</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$user</span><span style="color: #339933;">;</span> 
    <span style="color: #000088;">$userMutable</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setFirstName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Yanik'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h3>4.Utilisez la puissance de json_encode et limitez les points de contact</h3>
<p>Dans le développement d&#8217;application web, il est souvent nécessaire d&#8217;utiliser JavaScript. Trop souvent j&#8217;ai vu du code PHP générer par condition et concaténation plusieurs segments de code javascript. Que ce soit la construction de tableau, d&#8217;objet ou de fonction. Cette façon de produire du javascript rend la lecture et la compréhension du code javascript et PHP presque qu&#8217;impossible et le résultat ressemble souvent a un code offuscater.</p>
<p>Limitez les points de contact entre PHP et JavaScript. Dites-vous qu&#8217;a chaque fois que PHP produit un bout de JavaScript par un echo ou une concaténation c&#8217;est un point de contact.</p>
<p>Exemple A</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&lt;script&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$js</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'var user = new User({'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Point de contact</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$firstName</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$js</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;'<span style="color: #006699; font-weight: bold;">{$firstName}</span>',&quot;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$js</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'null,'</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// Point de contact</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$lastName</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$js</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;'<span style="color: #006699; font-weight: bold;">{$lastName}</span>',&quot;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$js</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'null,'</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// Point de contact</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$js</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;});&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Point de contact</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/script&gt;</pre></td></tr></table></div>

<p>Exemple B</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$prop</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'firstName'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Yanik'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'lastName'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Lupien'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;script&gt;
// Section Javascript
var prop = <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> jsonencode<span style="color: #009900;">&#40;</span><span style="color: #000088;">$prop</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>; // Point de contact
var user = new User(prop);
&lt;/script&gt;</pre></td></tr></table></div>

<p>Les deux codes si hauts donnent presque un résultat identique. Dans l&#8217;exemple A pour construire l&#8217;instance du user l&#8217;utilisation de la concaténation de segment javascript et variable PHP. Un des inconvénients de cette pratique est qu&#8217;il n&#8217;y a pas de prise en charge des valeurs avec quote.  Soit le Javasctipt va se briser soit il est possible d&#8217;injecter du javascript.</p>
<p>Dans l&#8217;exemple B chaque langage est clairement séparer le seul point de contact entre les deux est ou il y a l&#8217;assignation de la variable prop.</p>
<h3>5.Éradiquez la maladie du singleton / multiton</h3>
<p>Qui n&#8217;a pas déjà fais quelque chose qui ressemble a User::getInstance(4); ce patron de conception s&#8217;appelle un Multiton c&#8217;est l&#8217;équivalent d&#8217;un singleton, mais avec un cle par instance.  La classe User fait probablement partie de votre business logique de votre application. Ici se posent deux problématiques.</p>
<p>La première problématique, où se trouve la source de données?</p>
<p>La deuxième comment réutiliser votre classe avec une autre source de donnes ?</p>
<p>Dans la même logique je serais porter a faire une nouvelle méthode User::getInstanceFromFile(&#8216;user-6.txt&#8217;) pour récupérer une instance à partir d&#8217;un fichier&#8230; </p>
<p>Le singleton en soit n&#8217;est pas une mauvaise pratique c&#8217;est l&#8217;utilisation par appel statique qui n&#8217;est pas très bonne. Tout dépend du contexte bien sûr.</p>
<p>Conclusion : très rapidement la classe va se retrouver polluer d&#8217;une quantité incroyable de méthodes statique qui récupère des User de différentes façons et de plusieurs endroits différents avec plusieurs conditions différentes. Sans parler de dépendances externes que vous ajoutez à vos classes business.</p>
<h3>6.Fuyez les variables globales orientées objet</h3>
<p>Pour ceux qui ont déjà travaillé avec Zend_Framework, vous avez sûrement déjà vu la classe Zend_Registry. Cette classe est une belle variable globale orientée objet. Le programmeur qui utilise cette classe se sent en paix avec lui même, car il a la certitude de faire du beau code. C&#8217;est vrai qu&#8217;il n&#8217;y a pas le mot GLOBAL. Mais dans la réalité c&#8217;est une classe qui wrap une variable globale. Zend_Registry::getInstance() retourne une instance unique du registry peut importe l&#8217;emplacement ou nous somme dans l&#8217;application. Et par la suite il est possible de récupérer un élément par un nom.</p>
<p>Dite vous qu&#8217;a chaque fois que vous faite un appel statique a une classe extérieure sans l&#8217;avoir passé a la votre classe vous venez d&#8217;ajouter une dépendance externe qui risque de vous causer beaucoup de problèmes lorsque vous allez vouloir utiliser cette même classe dans un autre contexte.</p>
<p>Pour pallier à ceci, utiliser l&#8217;injection des dépendances. Si une votre class a besoin d&#8217;un logger pour son fonctionnement injectez lui.</p>
<h3>7. Définissez toujours de façon explicite l&#8217;origine des variables</h3>
<p>Avez-vous déjà défini une variable dans un fichier PHP et l&#8217;utiliser dans un autre ? Regardez l&#8217;exemple si dessous. Si nous somme dans le contexte du fichier index.php il n&#8217;est pas très clair de savoir de ou provient la variable $menu pourtant elle est la. Avec cette façon de développer, il y a aussi un gros risque de collision et d&#8217;erreurs.  Maintenant que se passe t&#8217;il si un développeur ajoute au fichier initialize.php une variable $menu ?</p>
<p><strong>config.php</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$config</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;myconfig.ini&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$menus</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Contact'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'About'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Products'</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p><strong>index.php</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'config.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'initialize.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$menus</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$menu</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #339933;">..</span> <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Arrêtez vous un instant et placez-vous dans les souliers d&#8217;un autre programmeur qui arrive dans le projet. Regardez le fichier index.php et posez-vous la question d&#8217;où provient $menus ? Etes vous en mesure de dire si c&#8217;est config.php ou initialize.php ?</p>
<p>Pour que le code soit lisible et facile à comprendre, il est toujours important de voir les entrées et sorties. Dans l&#8217;exemple il n&#8217;est pas possible de voir l&#8217;entrée / la provenance de $menu.</p>
<p>Pour corriger cette problématique, une façon simple serait simple d&#8217;ajouter une fonction et un return à la fin du fichier. L&#8217;utilisation d&#8217;une fonction rend toutes les variables utilisées dans le fichier config.php privé donc il n&#8217;affecter pas le scope globale. Le code se trouve aussi clarifie, puisque maintenant il est facile de suivre la provenance de la variable $menu.</p>
<p><strong>config.php</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> config<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$config</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;myconfig.ini&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$menus</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Contact'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'About'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Products'</span><span style="color: #009900;">&#41;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'menus'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$menus</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">return</span> config<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><strong>index.php</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$configs</span> <span style="color: #339933;">=</span> <span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'config.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$inits</span> <span style="color: #339933;">=</span> <span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'initialize.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'menus'</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$menu</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #339933;">..</span> <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Merci pour votre lecture.</p>
<h3>Références</h3>
<ul>
<li><a class="external" href="http://en.wikipedia.org/wiki/Dependency_injection">http://en.wikipedia.org/wiki/Dependency_injection</a></li>
<li><a class="external" href="http://fr.wikipedia.org/wiki/Singleton_%28patron_de_conception%29">http://fr.wikipedia.org/wiki/Singleton_%28patron_de_conception%29</a></li>
<li><a class="external" href="http://en.wikipedia.org/wiki/Multiton_pattern">http://en.wikipedia.org/wiki/Multiton_pattern</a></li>
<li><a class="external" href="http://en.wikipedia.org/wiki/Constant_%28programming%29">http://en.wikipedia.org/wiki/Constant_%28programming%29</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://yanik-lupien.com/articles-php/7-idees-pour-sameliorer-en-programmation-php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Facebook Widget</title>
		<link>http://yanik-lupien.com/realisations/outils-internet/facebook-widget</link>
		<comments>http://yanik-lupien.com/realisations/outils-internet/facebook-widget#comments</comments>
		<pubDate>Tue, 12 Oct 2010 22:40:16 +0000</pubDate>
		<dc:creator>Yanik Lupien</dc:creator>
				<category><![CDATA[Outils internet]]></category>

		<guid isPermaLink="false">http://yanik-lupien.com/?p=510</guid>
		<description><![CDATA[En collaboration avec Visicom Média, j’ai participé à la programmation ainsi qu&#8217;aux découpages et l&#8217;intégration d&#8217;un widget pour la VMN Toolbar. Ce widget permet de rester connecté à son compte Facebook. Une des particularités de cette application est qu&#8217;il utilise les serveurs de Facebook directement pour tous le contenue, donc une fois connecté, aucune requête [...]]]></description>
			<content:encoded><![CDATA[<p>En collaboration avec Visicom Média, j’ai participé à la  programmation ainsi qu&#8217;aux découpages et l&#8217;intégration d&#8217;un widget pour la VMN  Toolbar. Ce widget permet de rester connecté à son compte Facebook. Une des  particularités de cette application est qu&#8217;il utilise les serveurs de Facebook directement pour tous le contenue, donc une fois connecté, aucune requête n&#8217;est faite au serveur  de Visicom Média.</p>
<p>Technologies : PHP, Javascript/jQuery, XHTML/CSS, Facebook API</p>
<p>Adresse : <a href="http://apps.mystart.com/partners/default/widget_details.php?wid=1324" target="_blank">http://apps.mystart.com/partners/default/widget_details.php?wid=1324</a></p>
<p><a href="http://yanik-lupien.com/wp-content/uploads/2010/10/IEToolbarWidget.png"><img class="alignnone size-medium wp-image-515" title="IEToolbarWidget" src="http://yanik-lupien.com/wp-content/uploads/2010/10/IEToolbarWidget-550x402.png" alt="" width="550" height="402" /></a></p>
<p><span id="more-510"></span></p>
<p><a href="http://yanik-lupien.com/wp-content/uploads/2010/10/Login.png"><img class="alignnone size-full wp-image-511" title="Login" src="http://yanik-lupien.com/wp-content/uploads/2010/10/Login.png" alt="" width="321" height="555" /></a></p>
<p><a href="http://yanik-lupien.com/wp-content/uploads/2010/10/Home.png"><img class="alignnone size-full wp-image-512" title="Home" src="http://yanik-lupien.com/wp-content/uploads/2010/10/Home.png" alt="" width="321" height="555" /></a></p>
<p><a href="http://yanik-lupien.com/wp-content/uploads/2010/10/Home.png"></a><br />
<a href="http://yanik-lupien.com/wp-content/uploads/2010/10/NewsFeed.png"><img class="alignnone size-full wp-image-513" title="NewsFeed" src="http://yanik-lupien.com/wp-content/uploads/2010/10/NewsFeed.png" alt="" width="321" height="555" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://yanik-lupien.com/realisations/outils-internet/facebook-widget/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MyStart.com</title>
		<link>http://yanik-lupien.com/realisations/developpement-avance/mystart-com</link>
		<comments>http://yanik-lupien.com/realisations/developpement-avance/mystart-com#comments</comments>
		<pubDate>Sat, 18 Sep 2010 22:53:08 +0000</pubDate>
		<dc:creator>Yanik Lupien</dc:creator>
				<category><![CDATA[Développement avancé]]></category>

		<guid isPermaLink="false">http://yanik-lupien.com/?p=491</guid>
		<description><![CDATA[En collaboration avec Visicom Média, j&#8217;ai participé aux découpage, intégration et développement de certaines composantes de ce service de recherche en ligne tel que la boîte de recherche sur la page d&#8217;accueil ainsi que celle  sur la page de résultat. J&#8217;ai aussi développé le sélecteur de thème sous la boîte de recherche. Toutes les composantes [...]]]></description>
			<content:encoded><![CDATA[<p>En collaboration avec Visicom Média, j&#8217;ai participé  aux découpage, intégration et développement de certaines composantes de ce  service de recherche en ligne tel que la boîte de recherche sur la page  d&#8217;accueil ainsi que celle  sur la page de résultat. J&#8217;ai aussi développé le  sélecteur de thème sous la boîte de recherche. Toutes les composantes sont  entièrement dynamiques au niveau de la largeur. J&#8217;ai aussi développé l&#8217;outil de  proposition de mot clé.</p>
<p>Technologies utilisées : jQuery, XHTML/CSS</p>
<p>Adresse : <a href="http://www2.mystart.com/">http://www2.mystart.com/</a></p>
<p><a href="http://yanik-lupien.com/wp-content/uploads/2010/09/MyStart-SelectionTheme.png"><img class="alignnone size-medium wp-image-492" title="MyStart-SelectionTheme" src="http://yanik-lupien.com/wp-content/uploads/2010/09/MyStart-SelectionTheme-550x481.png" alt="" width="550" height="481" /></a></p>
<p><span id="more-491"></span></p>
<p><a href="http://yanik-lupien.com/wp-content/uploads/2010/09/MyStart-KeywordSuggestion.png"><img class="alignnone size-medium wp-image-493" title="MyStart-KeywordSuggestion" src="http://yanik-lupien.com/wp-content/uploads/2010/09/MyStart-KeywordSuggestion-550x481.png" alt="" width="550" height="481" /></a></p>
<p><a href="http://yanik-lupien.com/wp-content/uploads/2010/09/MyStart-SearchResult.png"><img class="alignnone size-medium wp-image-498" title="MyStart-SearchResult" src="http://yanik-lupien.com/wp-content/uploads/2010/09/MyStart-SearchResult-550x481.png" alt="" width="550" height="481" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://yanik-lupien.com/realisations/developpement-avance/mystart-com/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Groupe Galland &#8211; Site web</title>
		<link>http://yanik-lupien.com/realisations/decoupe-integration-cms/groupe-galland-site-web</link>
		<comments>http://yanik-lupien.com/realisations/decoupe-integration-cms/groupe-galland-site-web#comments</comments>
		<pubDate>Sat, 18 Sep 2010 22:40:05 +0000</pubDate>
		<dc:creator>Yanik Lupien</dc:creator>
				<category><![CDATA[Découpe et intégration CMS]]></category>

		<guid isPermaLink="false">http://yanik-lupien.com/?p=482</guid>
		<description><![CDATA[Dans ce projet, réalisé avec Tapage Communication, j&#8217;ai découpé, intégré et développé le site web français et anglais. J&#8217;ai développé des pages personnalisées pour l&#8217;affichage  d&#8217;autobus selon une structure de données précises. J&#8217;ai monté les différents formulaires pour la saisie de données sur le site web. J&#8217;ai aussi utilisé la libraire PHPExcel pour la production [...]]]></description>
			<content:encoded><![CDATA[<p>Dans ce projet, réalisé avec Tapage Communication, j&#8217;ai découpé, intégré et développé le site web  français et anglais. J&#8217;ai développé des pages personnalisées pour l&#8217;affichage  d&#8217;autobus selon une structure de données précises. J&#8217;ai monté les  différents formulaires pour la saisie de données sur le site web. J&#8217;ai aussi  utilisé la libraire PHPExcel pour la production de rapport de satisfaction selon  les données entrées sur les différents rapports par les clients. Pour la partie administrative, j’ai développé un plugin WordPress pour l’édition de données spécifiques aux autobus Groupe Galland. L’objectif était de simplifier et de normaliser les informations de chaque fiche d’autobus.</p>
<p>Technologies utilisées : PHP/MySQL, jQuery, XHTML/CSS et GD, PHPExcel, WordPress</p>
<p>Adresse :  <a href="http://www.autobusgalland.com/" target="_blank">http://www.autobusgalland.com/</a></p>
<p><a href="http://yanik-lupien.com/wp-content/uploads/2010/09/SiteWeb-Accueil.png"><img class="alignnone size-medium wp-image-483" title="SiteWeb-Accueil" src="http://yanik-lupien.com/wp-content/uploads/2010/09/SiteWeb-Accueil-550x841.png" alt="" width="550" height="841" /></a></p>
<p><span id="more-482"></span></p>
<p><a href="http://yanik-lupien.com/wp-content/uploads/2010/09/SiteWeb-NosAutobus.png"><img class="alignnone size-medium wp-image-484" title="SiteWeb-NosAutobus" src="http://yanik-lupien.com/wp-content/uploads/2010/09/SiteWeb-NosAutobus-550x764.png" alt="" width="550" height="764" /></a></p>
<p><a href="http://yanik-lupien.com/wp-content/uploads/2010/09/WordpressPersonnalise-Autobus.png"><img class="alignnone size-medium wp-image-485" title="WordpressPersonnalise-Autobus" src="http://yanik-lupien.com/wp-content/uploads/2010/09/WordpressPersonnalise-Autobus-550x802.png" alt="" width="550" height="802" /></a></p>
<p><a href="http://yanik-lupien.com/wp-content/uploads/2010/09/WordpressPersonnalise-DemandeSatisfaction.png"><img class="alignnone size-medium wp-image-486" title="WordpressPersonnalise-DemandeSatisfaction" src="http://yanik-lupien.com/wp-content/uploads/2010/09/WordpressPersonnalise-DemandeSatisfaction-550x531.png" alt="" width="550" height="531" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://yanik-lupien.com/realisations/decoupe-integration-cms/groupe-galland-site-web/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VMN Toolbar &#8211; Web TV Widget</title>
		<link>http://yanik-lupien.com/realisations/developpement-avance/vmn-toolbar-web-tv-widget</link>
		<comments>http://yanik-lupien.com/realisations/developpement-avance/vmn-toolbar-web-tv-widget#comments</comments>
		<pubDate>Thu, 26 Aug 2010 03:23:11 +0000</pubDate>
		<dc:creator>Yanik Lupien</dc:creator>
				<category><![CDATA[Développement avancé]]></category>

		<guid isPermaLink="false">http://yanik-lupien.com/?p=468</guid>
		<description><![CDATA[Pour Visicom Media, j&#8217;ai développé un widget pour la VMN Toolbar. Technologies utilisé : PHP/MySQL, jQuery, AJAX, XHTML/CSS, JSON, VMN Toolbar Adresse : http://apps.mystart.com/partners/default/widget_details.php?wid=1300]]></description>
			<content:encoded><![CDATA[<p>Pour Visicom Media, j&#8217;ai développé un widget pour la VMN Toolbar.</p>
<p>Technologies utilisé : PHP/MySQL, jQuery, AJAX, XHTML/CSS, JSON, VMN Toolbar</p>
<p>Adresse : <a href="http://apps.mystart.com/partners/default/widget_details.php?wid=1300">http://apps.mystart.com/partners/default/widget_details.php?wid=1300</a></p>
<p><a href="http://yanik-lupien.com/wp-content/uploads/2010/08/interfaces.png"><img class="alignnone size-medium wp-image-467" title="interfaces" src="http://yanik-lupien.com/wp-content/uploads/2010/08/interfaces-550x538.png" alt="" width="550" height="538" /></a></p>
<p><span id="more-468"></span><a href="http://yanik-lupien.com/wp-content/uploads/2010/08/interface.png"><img class="alignnone size-full wp-image-469" title="interface" src="http://yanik-lupien.com/wp-content/uploads/2010/08/interface.png" alt="" width="312" height="567" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://yanik-lupien.com/realisations/developpement-avance/vmn-toolbar-web-tv-widget/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Centre bodyshop &#8211; Section membres</title>
		<link>http://yanik-lupien.com/realisations/decoupe-integration-cms/centre-bodyshop-section-membres</link>
		<comments>http://yanik-lupien.com/realisations/decoupe-integration-cms/centre-bodyshop-section-membres#comments</comments>
		<pubDate>Thu, 26 Aug 2010 03:14:49 +0000</pubDate>
		<dc:creator>Yanik Lupien</dc:creator>
				<category><![CDATA[Découpe et intégration CMS]]></category>

		<guid isPermaLink="false">http://yanik-lupien.com/?p=463</guid>
		<description><![CDATA[Pour Tapage Communication, j&#8217;ai monté la section membre des centres bodyshop. Technologies utilisées : PHP/MySQL, XHTML/CSS, jQuery Adresse : http://www.centrebodyshop.com/fr/services]]></description>
			<content:encoded><![CDATA[<p>Pour Tapage Communication, j&#8217;ai monté la section membre des centres bodyshop.</p>
<p>Technologies utilisées : PHP/MySQL, XHTML/CSS, jQuery</p>
<p>Adresse : <a href="http://www.centrebodyshop.com/fr/services" target="_blank">http://www.centrebodyshop.com/fr/services</a></p>
<p><a href="http://yanik-lupien.com/wp-content/uploads/2010/08/Partenaires.png"><img class="alignnone size-medium wp-image-461" title="Partenaires" src="http://yanik-lupien.com/wp-content/uploads/2010/08/Partenaires-550x585.png" alt="" width="550" height="585" /></a></p>
<p><span id="more-463"></span></p>
<p><a href="http://yanik-lupien.com/wp-content/uploads/2010/08/Partenaires-Open.png"><img class="alignnone size-medium wp-image-462" title="Partenaires-Open" src="http://yanik-lupien.com/wp-content/uploads/2010/08/Partenaires-Open-550x585.png" alt="" width="550" height="585" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://yanik-lupien.com/realisations/decoupe-integration-cms/centre-bodyshop-section-membres/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fraisebec &#8211; Concours</title>
		<link>http://yanik-lupien.com/realisations/decoupe-integration-cms/fraisebec-concours</link>
		<comments>http://yanik-lupien.com/realisations/decoupe-integration-cms/fraisebec-concours#comments</comments>
		<pubDate>Thu, 26 Aug 2010 03:13:05 +0000</pubDate>
		<dc:creator>Yanik Lupien</dc:creator>
				<category><![CDATA[Découpe et intégration CMS]]></category>

		<guid isPermaLink="false">http://yanik-lupien.com/?p=458</guid>
		<description><![CDATA[Pour Tapage Communication, j’ai monté ce formulaire de concours. Addresse : http://fraisebec.tapage-web.com/inscription.php]]></description>
			<content:encoded><![CDATA[<p>Pour Tapage Communication, j’ai monté ce formulaire de concours.</p>
<p>Addresse : <a href="http://fraisebec.tapage-web.com/inscription.php" target="_blank">http://fraisebec.tapage-web.com/inscription.php</a></p>
<p><a href="http://yanik-lupien.com/wp-content/uploads/2010/08/ConcoursFormulaire.png"><img class="alignnone size-medium wp-image-459" title="ConcoursFormulaire" src="http://yanik-lupien.com/wp-content/uploads/2010/08/ConcoursFormulaire-550x895.png" alt="" width="550" height="895" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://yanik-lupien.com/realisations/decoupe-integration-cms/fraisebec-concours/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

