<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress.com" -->
<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/"
	>

<channel>
	<title>designpattern &amp;laquo; WordPress.com Tag Feed</title>
	<link>http://en.wordpress.com/tag/designpattern/</link>
	<description>Feed of posts on WordPress.com tagged "designpattern"</description>
	<pubDate>Mon, 28 Dec 2009 06:48:12 +0000</pubDate>

	<generator>http://en.wordpress.com/tags/</generator>
	<language>en</language>

<item>
<title><![CDATA[Silverlight 3.0, RIA services and MVVM]]></title>
<link>http://subodhnpushpak.wordpress.com/2009/07/20/silverlight-3-0-ria-services-and-mvvm/</link>
<pubDate>Mon, 20 Jul 2009 10:19:29 +0000</pubDate>
<dc:creator>subodhnpushpak</dc:creator>
<guid>http://subodhnpushpak.wordpress.com/2009/07/20/silverlight-3-0-ria-services-and-mvvm/</guid>
<description><![CDATA[MVVM == Model View ViewModel Pattern is a MUST follow pattern in Silverlight (WPF). here is why… Pro]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>MVVM == Model View ViewModel Pattern is a MUST follow pattern in Silverlight (WPF). here is why…</p>
<p>Problems it solves:</p>
<blockquote><p>•Tight coupling of layers (ex a query in the UI)</p>
<p>•Unit testing is hard/impossible, only functional testing is possible</p>
<p>•Assures codes still works correct after a change</p>
</blockquote>
<p>•ViewModel </p>
<blockquote><p>•Provides View with data model and behavior</p>
<p>•View will bind to ViewModel</p>
<p>•Wraps data access entirely</p>
</blockquote>
<p>In light of new technologies like RIA services (which provides CRUD) operations out of the box it is imperative that users are tempted to overlook MVVM for sake of simplicity!!! However, the goodies MVVM brings along holds good in RIA services well… So what the roadmap to have MVVM , silverlight and RIA services???? I havnt found much on google (&#38; BING!!!) but here is my humble take on that.</p>
<p>I plan to write more in my forthcoming blog but <a href="http://cid-db22cddc0bcaf16e.skydrive.live.com/self.aspx/Silverlight%203.0/MVVM/Silverlight.Framework.zip" target="_blank">here is one example using nInject</a>. </p>
<p>nInject is lightweight DI framework and is helpful in injecting VIEWMODEL right into XAML code!!! here is how…</p>
<div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;line-height:12pt;background-color:#f4f4f4;width:97.5%;font-family:&#39;direction:ltr;max-height:200px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;margin:20px 0 10px;padding:4px;" id="codeSnippetWrapper">
<div style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0;" id="codeSnippet">
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> Title=<span style="color:#006080;">&#34;Home&#34;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span>   DataContext=<span style="color:#006080;">&#34;{Binding Path=HomeViewModel, Source={StaticResource serviceLocator}}&#34;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span>   Style=<span style="color:#006080;">&#34;{StaticResource PageStyle}&#34;</span>&#62;</pre>
<p><!--CRLF--></div>
</div>
<p>Notice … the datacontext (VIEW MODEL) is injected using ServiceLocator!! the service locater is itself a resource defined in APP.xaml</p>
<div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;line-height:12pt;background-color:#f4f4f4;width:97.5%;font-family:&#39;direction:ltr;max-height:200px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;margin:20px 0 10px;padding:4px;" id="codeSnippetWrapper">
<div style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0;" id="codeSnippet">
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> Application   </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span>   x:Class=<span style="color:#006080;">&#34;SilverlightApp.App&#34;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span>   xmlns:local=<span style="color:#006080;">&#34;clr-namespace:SilverlightApp.ViewModel&#34;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span>   xmlns=<span style="color:#006080;">&#34;http://schemas.microsoft.com/winfx/2006/xaml/presentation&#34;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   5:</span>   xmlns:x=<span style="color:#006080;">&#34;http://schemas.microsoft.com/winfx/2006/xaml&#34;</span>&#62;</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   6:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   7:</span>   &#60;Application.Resources&#62;</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   8:</span>   </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   9:</span>     &#60;ResourceDictionary&#62;</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  10:</span>       &#60;ResourceDictionary.MergedDictionaries&#62;</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  11:</span>         &#60;ResourceDictionary Source=<span style="color:#006080;">&#34;Assets/Styles.xaml&#34;</span>/&#62;</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  12:</span>       &#60;/ResourceDictionary.MergedDictionaries&#62;</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  13:</span>     &#60;/ResourceDictionary&#62;</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  14:</span>         &#60;local:ServiceLocator x:Key=<span style="color:#006080;">&#34;serviceLocator&#34;</span> /&#62;</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  15:</span>     &#60;/Application.Resources&#62;</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  16:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  17:</span> &#60;/Application&#62;</pre>
<p><!--CRLF--></div>
</div>
<p>and Ninject code for Service Locater goes like…</p>
<div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;line-height:12pt;background-color:#f4f4f4;width:97.5%;font-family:&#39;direction:ltr;max-height:200px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;margin:20px 0 10px;padding:4px;" id="codeSnippetWrapper">
<div style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0;" id="codeSnippet">
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> <span style="color:#0000ff;">namespace</span> SilverlightApp.ViewModel</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span> {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span>     <span style="color:#0000ff;">using</span> Ninject.Core;</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span>     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> ServiceLocator</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   5:</span>     {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   6:</span>         <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">readonly</span> IKernel kernel;</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   7:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   8:</span>         <span style="color:#0000ff;">static</span> ServiceLocator()</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   9:</span>         {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  10:</span>             <span style="color:#0000ff;">if</span> (kernel == <span style="color:#0000ff;">null</span>)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  11:</span>             {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  12:</span>                 kernel = <span style="color:#0000ff;">new</span> StandardKernel(<span style="color:#0000ff;">new</span> Module());</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  13:</span>             }</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  14:</span>         }</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  15:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  16:</span>         <span style="color:#0000ff;">public</span> HomeViewModel HomeViewModel</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  17:</span>         {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  18:</span>             get</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  19:</span>             {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  20:</span>                 <span style="color:#0000ff;">return</span> kernel.Get&#60;HomeViewModel&#62;(); </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  21:</span>             }</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  22:</span>         }</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  23:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  24:</span>         <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">static</span> T Get&#60;T&#62;()</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  25:</span>         {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  26:</span>             <span style="color:#0000ff;">return</span> kernel.Get&#60;T&#62;();</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  27:</span>         }</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  28:</span>     }</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  29:</span> }</pre>
<p><!--CRLF--></div>
</div>
<p>&#160;</p>
<p>The commands are taken care by the <strong>SLExtensions. here is how…</strong></p>
<p>I will be using and blogging about the following DI … Please feel free to write more… if you have anything to add..</p>
<p>1. Nikhil Silverlight FX… This is really good stuff; the only thing which is “does NOT” goes down well (to most of developers) is use of customized controls. Having said that i must say, personally, i love this approach and how Nikhil keep updating it with newest stuff!!!</p>
<p>2. CAB(Prism): I personally think it is more opt for WPF. Having said that it also follows “injection through interface” paradigm.. which sometimes introduces too much hassles…</p>
<p>3. MEF. Latest from Microsoft. Very promising, however yet to mature as a tool. </p>
<p>4. <a href="http://www.codeplex.com/caliburn" target="_blank">Caliburn</a>: Excellent tool. I found it at codeplex… </p>
<p>&#160;</p>
<p>My plan is to retest each of the above wrt SL3.0, RIA services abd MVVM in context abd post results on this blog.. and get more tractions on the results i get to..</p>
<p>Keep jotting your comments…</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:c8264260-5718-4ed8-9875-beb4a9c910c4" class="wlWriterEditableSmartContent">Technorati Tags: <a href="http://technorati.com/tags/MVVM" rel="tag">MVVM</a>,<a href="http://technorati.com/tags/Silverlight" rel="tag">Silverlight</a>,<a href="http://technorati.com/tags/RIA+Services" rel="tag">RIA Services</a></div>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Implémentation du pattern IoC]]></title>
<link>http://hadf.wordpress.com/2009/05/29/implementation-du-pattern-io/</link>
<pubDate>Fri, 29 May 2009 20:47:16 +0000</pubDate>
<dc:creator>hadf</dc:creator>
<guid>http://hadf.wordpress.com/2009/05/29/implementation-du-pattern-io/</guid>
<description><![CDATA[J&#8217;ai eu le temps dans le train de réfléchir à quelques problèmes qui s&#8217;annoncent dans l]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>J&#8217;ai eu le temps dans le train de réfléchir à quelques problèmes qui s&#8217;annoncent dans l&#8217;évolution à venir de Swinger. Jusqu&#8217;à présent, j&#8217;ai laissé de côté les composants complexes de Swing tels que les JTree ou encore les JTable. La raison est que cela nécessite de pouvoir spécifier des valeurs à insérer dans le model comme dans le cas des tables en HTML. J&#8217;avais commencé à introduire une balise &#60;item&#62; qui était utilisée pour les JList, mais je suis finalement revenu en arrière car l&#8217;approche n&#8217;était pas la bonne. Les items ne font pas partie de la couche Vue mais de la couche Model. Il n&#8217;était donc pas judicieux de traiter communément ces deux types d&#8217;élément.</p>
<p>La solution que j&#8217;adopterai du point de vue du langage sera l&#8217;introduction des namespaces. Ils permettront d&#8217;identifier les différentes couches de l&#8217;api Swing. Du point de vue de l&#8217;implémentation, je suis toujours confronté à la nécessité de différencier les traitements associés à ces couches. Pour cela, j&#8217;adopterai une implémentation simplifiée du pattern Inversion of Control.</p>
<p>Prenons comme hypothèse de départ que vous êtes en présence d&#8217;une architecture dans laquelle l&#8217;<em>implémentation d&#8217;une responsabilité varie selon le type de composant passé en paramètre</em>.</p>
<p>Plutôt que d&#8217;implémenter la responsabilité dans une seule méthode avec des vérifications de casting, je dispatch la responsabilité dans des méthodes différentes selon le type d&#8217;objet à traiter, et je délègue l&#8217;appel de la méthode idoine au niveau des composants subalternes.</p>
<p>Typiquement, l&#8217;implémentation sera celle-ci :</p>
<pre>public class Child1 implements IoC {
    @Override
    public void delegate(Parent parent) {
        parent.method1();
    }
}

public class Child2 implements IoC {
    @Override
    public void delegate(Parent parent) {
        parent.method2();
    }
}</pre>
<p>Cette approche me permettra de conserver le caractère modulaire de Swinger. Tout type de composant pourra être ajouté à un parent, ça sera le composant fils qui déterminera de quel manière il sera ajouté à son parent. Actuellement, seule la méthode Container.add() est utilisée. Avec cette nouvelle architecture, il sera même possible d&#8217;ajouter un layout à un conteneur grâce à une balise. Je rappelle que c&#8217;est ce problème qui m&#8217;avait amené à l&#8217;origine à implémenter CSS. Je n&#8217;ai pas pour autant l&#8217;intention d&#8217;abandonner CSS car je pense que cela apportera une plus grande simplicité dans la création d&#8217;IHM.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Sample code of Design pattern(Head First)]]></title>
<link>http://nishantrana.wordpress.com/?p=24</link>
<pubDate>Fri, 28 Sep 2007 14:26:58 +0000</pubDate>
<dc:creator>Nishant Rana</dc:creator>
<guid>http://nishantrana.wordpress.com/?p=24</guid>
<description><![CDATA[using System;public interface FlyBehavior{void Fly();} public class FlyWithWings : FlyBehavior{publi]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><font size="1" color="#0000ff">using<font size="1"> System;</font></font><font size="1" color="#0000ff"><font size="1" color="#0000ff">public<font size="1"> </font><font size="1" color="#0000ff">interface</font><font size="1"> </font><font size="1" color="#2b91af">FlyBehavior</font></font></font><font size="1" color="#0000ff"><font size="1">{</font><font size="1"><font size="1" color="#0000ff">void</font><font size="1"> Fly();</font><font size="1">}</font></font></p>
<p></font><font size="1" color="#0000ff">public<font size="1"> </font><font size="1" color="#0000ff">class</font><font size="1"> </font><font size="1" color="#2b91af">FlyWithWings</font><font size="1"> : </font><font size="1" color="#2b91af">FlyBehavior</font></font><font size="1" color="#0000ff"><font size="1">{</font></font><font size="1" color="#0000ff">public</font><font size="1"> </font><font size="1" color="#0000ff">void</font><font size="1"> Fly()</font><font size="1">{</font><font size="1" color="#2b91af">Console</font><font size="1">.WriteLine(</font><font size="1" color="#a31515">&#8220;I can fly cause i have wings to fly&#8221;</font><font size="1">);</font><font size="1">}</font><font size="1">}</font><font size="1"><font size="1" color="#0000ff">public<font size="1"> </font><font size="1" color="#0000ff">class</font><font size="1"> </font><font size="1" color="#2b91af">FlyNoWay</font><font size="1"> : </font><font size="1" color="#2b91af">FlyBehavior</font></font></p>
<p></font><font size="1">{</font><font size="1" color="#0000ff">#region</font><font size="1"> FlyBehavior Members</font><font size="1" color="#0000ff">public</font><font size="1"> </font><font size="1" color="#0000ff">void</font><font size="1"> Fly()</font><font size="1">{</font><font size="1"><font size="1" color="#2b91af">Console</font><font size="1">.WriteLine(</font><font size="1" color="#a31515">&#8220;I can&#8217;t fly cause i have no wings&#8221;</font><font size="1">);}</font></font><font size="1"><font size="1" color="#0000ff">#endregion</font></p>
<p><font size="1">}</font><font size="1"><font size="1" color="#0000ff">public<font size="1"> </font><font size="1" color="#0000ff">abstract</font><font size="1"> </font><font size="1" color="#0000ff">class</font><font size="1"> </font><font size="1" color="#2b91af">Duck</font></font></font></p>
<p></font><font size="1">{</font><font size="1" color="#0000ff">public</font><font size="1"> </font><font size="1" color="#2b91af">FlyBehavior</font><font size="1"> flyB;</font><font size="1" color="#0000ff">public</font><font size="1"> Duck()</font><font size="1">{</font><font size="1">}</font><font size="1" color="#0000ff">public</font><font size="1"> </font><font size="1" color="#0000ff">abstract</font><font size="1"> </font><font size="1" color="#0000ff">void</font><font size="1"> Display();</font><font size="1"> </font><font size="1" color="#0000ff">public</font><font size="1"> </font><font size="1" color="#0000ff">void</font><font size="1"> performFly()</font><font size="1">{</font><font size="1">flyB.Fly();</font><font size="1">}</p>
<p><font size="1" color="#0000ff">public</font><font size="1"> </font><font size="1" color="#0000ff">void</font><font size="1"> swim()</font><font size="1">{</font><font size="1"><font size="1" color="#2b91af">Console</font><font size="1">.WriteLine(</font><font size="1" color="#a31515">&#8220;All duck float that&#8217;s why they swim&#8221;</font><font size="1">);</font><font size="1">}</font></font></p>
<p></font><font size="1" color="#0000ff">public</font><font size="1"> </font><font size="1" color="#0000ff">void</font><font size="1"> setFlyBehavior(</font><font size="1" color="#2b91af">FlyBehavior</font><font size="1"> fb)</font><font size="1">{</font><font size="1">flyB=fb;</font><font size="1">}</p>
<p>}</p>
<p></font><font size="1" color="#0000ff">public</font><font size="1"> </font><font size="1" color="#0000ff">class</font><font size="1"> </font><font size="1" color="#2b91af">DonaldDuck</font><font size="1"> :</font><font size="1" color="#2b91af">Duck</font><font size="1"> </font><font size="1">{</font><font size="1"><font size="1" color="#0000ff">public</font><font size="1"> DonaldDuck()</font><font size="1">{flyB=</font></font><font size="1"><font size="1" color="#0000ff">new</font><font size="1"> </font><font size="1" color="#2b91af">FlyWithWings</font><font size="1">();</font><font size="1">}</font><font size="1"><font size="1" color="#0000ff">public</font><font size="1"> </font><font size="1" color="#0000ff">override</font><font size="1"> </font><font size="1" color="#0000ff">void</font><font size="1"> Display()</font><font size="1">{</font></font></p>
<p></font><font size="1" color="#2b91af">Console</font><font size="1">.WriteLine(</font><font size="1" color="#a31515">&#8221; I am a real Donald Duck&#8221;</font><font size="1">);</font><font size="1">}</font><font size="1">}</font><font size="1"><font size="1" color="#0000ff">public<font size="1"> </font><font size="1" color="#0000ff">class</font><font size="1"> </font><font size="1" color="#2b91af">DuckSimulator</font></font><font size="1" color="#0000ff"><font size="1">{</font></font></p>
<p></font><font size="1" color="#0000ff">public</font><font size="1"> </font><font size="1" color="#0000ff">static</font><font size="1"> </font><font size="1" color="#0000ff">void</font><font size="1"> Main()</font><font size="1">{</font><font size="1" color="#2b91af">Duck</font><font size="1"> dd=</font><font size="1" color="#0000ff">new</font><font size="1"> </font><font size="1" color="#2b91af">DonaldDuck</font><font size="1">();</font><font size="1">dd.performFly();</font><font size="1"><font size="1" color="#008000">// donald duck can&#8217;t fly now</font></font><font size="1"> </font><font size="1">dd.setFlyBehavior(</font><font size="1" color="#0000ff">new</font><font size="1"> </font><font size="1" color="#2b91af">FlyNoWay</font><font size="1">() );</font><font size="1">dd.performFly();</font><font size="1">}</font><font size="1">}</p>
<p></font></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[null parameters considered less harmful]]></title>
<link>http://silkandspinach.net/2004/11/27/null-parameters-considered-less-harmful/</link>
<pubDate>Sat, 27 Nov 2004 22:26:30 +0000</pubDate>
<dc:creator>Kevin Rutherford</dc:creator>
<guid>http://silkandspinach.net/2004/11/27/null-parameters-considered-less-harmful/</guid>
<description><![CDATA[Mike Feathers has posted an article in which he defends the use of null parameters, but only under c]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Mike Feathers has posted an <a href="http://www.artima.com/weblogs/viewpost.jsp?thread=81895">article</a> in which he defends the use of null parameters, but only under certain circumstances: He likes them as parameters to constructors when building lightweight objects in tests.</p>
<p>As you know by now, dear reader, I have railed <a href="/blog/2004/07/if.html">long and loud</a> against the use of null parameters. And so I find myself disagreeing with Mike on this topic. <em>[Mike, I would have commented directly on your blog, but why do I need an Artima account to do so?]</em></p>
<p>Mike suggests that it is always worth trying a line such as</p>
<pre>ADBDocument doc = new ADBDocument(null, 0, null);</pre>
<p>when writing a test. If it works, he says, you get a lightweight object that can be just good enough to write the test and continue. But is the code now truly intention-revealing? If it were indeed sensible or feasible to create a <code>ADBDocument</code> with no inputs to the constructor, perhaps a zero-argument constructor should have been provided; or a factory method called <code>newUnprintableDocument()</code>? It seems to me that there is now a brittle relationship between the test method and the implementation of at least one constructor for the <code>ADBDocument</code> class, and that makes me nervous.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[avoid boolean parameters]]></title>
<link>http://silkandspinach.net/2004/07/15/avoid-boolean-parameters/</link>
<pubDate>Thu, 15 Jul 2004 11:33:11 +0000</pubDate>
<dc:creator>Kevin Rutherford</dc:creator>
<guid>http://silkandspinach.net/2004/07/15/avoid-boolean-parameters/</guid>
<description><![CDATA[You are tempted to create a method with a boolean argument. The caller will set the argument to true]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>You are tempted to create a method with a boolean argument.  The caller will set the argument to <code>true</code> or <code>false</code> depending on which code path he wishes the called method to take.  This is an extremely convenient way to add a small degree of configurability to an algorithm, and means that both paths through the called method can share setup and cleanup code.</p>
<pre>
<u>class MyClass</u>

    void dosomething(boolean followPathA) {
        // setup
        if (followPathA)
            // pathA
        else
            // pathB
        // cleanup
    }</pre>
<p><strong>However,</strong> the use of a boolean argument reduces readability.  For example, in a method such as<br />
<code>workspace.createFile(name, true)</code>, what does &#8220;false&#8221; mean?  It is much more intention-revealing to call a method such as <code>workspace.createTempFile(name)</code>.  Furthermore, boolean arguments always create duplication, either of code or of responsibility, and often of a very insidious nature.  This is because the called method contains a runtime test to decide between two different code paths, despite thet fact that the calling method <em>already knows which branch it requires</em>!  The duplication not only wastes a little runtime, it also spreads knowledge and responsibility further than is necessary.  The resulting code is more closely coupled than the design it represents.  These effects are magnified exponentially each time the boolean argument is passed on in a further method call.</p>
<p><strong>Therefore</strong> avoid the need for a boolean argument by creating two versions of the method, in which the meaning of the boolean is reflected in the names of the new methods.  For example, replace</p>
<ul>
<pre>File createFile(String name, boolean istemp)</pre>
</ul>
<p>by</p>
<ul>
<pre>
File createFile(String name)
File createTempFile(String name)</pre>
</ul>
<p>If the resulting new methods have similar logic, extract the duplicate code into shared methods that can be called by each.</p>
<p>(Here&#8217;s a <a href="http://www.cuj.com/documents/s=7977/cujcexp2011hyslop/hyslop.htm">fun story</a> on a related theme.)</p>
</div>]]></content:encoded>
</item>

</channel>
</rss>
