<?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>Sadek Drobi's Blog &#187; Martin Fowler</title>
	<atom:link href="http://sadekdrobi.com/category/martin-fowler/feed/" rel="self" type="application/rss+xml" />
	<link>http://sadekdrobi.com</link>
	<description>Sadek Drobi</description>
	<lastBuildDate>Tue, 08 Mar 2011 22:56:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>DSLs bringing the end of single language development?</title>
		<link>http://sadekdrobi.com/2007/08/07/dsls-bringing-the-end-of-single-language-development/</link>
		<comments>http://sadekdrobi.com/2007/08/07/dsls-bringing-the-end-of-single-language-development/#comments</comments>
		<pubDate>Tue, 07 Aug 2007 17:20:55 +0000</pubDate>
		<dc:creator>Sadache</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[DSL]]></category>
		<category><![CDATA[Domain Driven Design]]></category>
		<category><![CDATA[Functional Programming]]></category>
		<category><![CDATA[Martin Fowler]]></category>

		<guid isPermaLink="false">http://sadekdrobi.com/2007/08/07/dsls-bringing-the-end-of-single-language-development/</guid>
		<description><![CDATA[My second contribution in InfoQ. An interesting news post about DSLs, and language oriented programming.
http://www.infoq.com/news/2007/08/multi-lingual-programming
]]></description>
			<content:encoded><![CDATA[<p>My second contribution in InfoQ. An interesting news post about DSLs, and language oriented programming.</p>
<p><a href="http://www.infoq.com/news/2007/08/multi-lingual-programming">http://www.infoq.com/news/2007/08/multi-lingual-programming</a></p>
]]></content:encoded>
			<wfw:commentRss>http://sadekdrobi.com/2007/08/07/dsls-bringing-the-end-of-single-language-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Refx :: Martin Fowler on MODIFIABILITY (QCon)</title>
		<link>http://sadekdrobi.com/2007/03/14/refx-martin-fowler-on-modifiability-qcon/</link>
		<comments>http://sadekdrobi.com/2007/03/14/refx-martin-fowler-on-modifiability-qcon/#comments</comments>
		<pubDate>Wed, 14 Mar 2007 14:01:18 +0000</pubDate>
		<dc:creator>Sadache</dc:creator>
				<category><![CDATA[Agile Programming]]></category>
		<category><![CDATA[Conferences]]></category>
		<category><![CDATA[Domain Driven Design]]></category>
		<category><![CDATA[Martin Fowler]]></category>
		<category><![CDATA[QCon2007]]></category>
		<category><![CDATA[Refactoring]]></category>

		<guid isPermaLink="false">http://sadekdrobi.com/?p=51</guid>
		<description><![CDATA[

In agile development process, the Design task is still important, we just changed the way we do it to evolutionary design rather than un upfront one. Yet, In some cases we cant defer design decision till the end, and we do need to do them in an upfront style.Â 

Do the simplest thing that works ( [...]]]></description>
			<content:encoded><![CDATA[<p><a atomicselection="true" href="http://sadekdrobi.com/wp-content/uploads/2007/03/windowslivewriterrefxmartinfowleronmodifiabilityqcon-d2cadsc-0048004841.jpg"><img border="0" width="457" src="http://sadekdrobi.com/wp-content/uploads/2007/03/windowslivewriterrefxmartinfowleronmodifiabilityqcon-d2cadsc-00480048-thumb22.jpg" height="304" style="border-width: 0px" /></a></p>
<ul>
<li>In agile development process, the Design task is still important, we just changed the way we do it to evolutionary design rather than un upfront one. Yet, In some cases we cant defer design decision till the end, and we do need to do them in an upfront style.Â </li>
</ul>
<blockquote><p>Do the simplest thing that works ( Kent Beck )</p></blockquote>
<ul>
<li>Kent Beck commented on this that &#8220;The simplest thing is not the most stupid !&#8221;</li>
<li>Software SHOULD have a model, and cant be only tachtical all the time.</li>
<li>In a Lean Software Development we dont make decisions before we really have to, but we have to do them once!Â or otherwise we will be taken as not able toÂ make decisions.</li>
<li>Try different choices on different teams, building different implementations, find that last minute where you can decide.</li>
<li>The key to modifiability is encapsulation and abstraction.</li>
<li>The key question is : Do i have to make the decision yet?</li>
<li>The Domain Model is made! The task is to reflect it well in the software.</li>
<li>Isolate Domain models from technical ones</li>
<li>Preparing a ground for Modifiability</li>
<li>Making a decision of when to make a decision</li>
<li>Discuss well with business people to reflect the model</li>
<li>Html is undoable because there is not a ig investement in doing it</li>
<li>Breaking encapsulation for a decision makes it a bad decision</li>
<li>redability of code</li>
<li>Unit testing to guarantee encapsulation</li>
<li>Software evolves anyway, maintainability IS an issue!</li>
<li>Encapsulation is about keeping secrets.</li>
<li>Pair progamming for teaching design, that will raise team&#8217;s productivity as a whole</li>
<li>Lessons can be learnt better through modifiability than through upfront teaching</li>
<li>Struggle for reversable architecture</li>
</ul>
<p><a atomicselection="true" href="http://sadekdrobi.com/wp-content/uploads/2007/03/windowslivewriterrefxmartinfowleronmodifiabilityqcon-d2cadsc-0046004611.jpg"><img border="0" width="240" src="http://sadekdrobi.com/wp-content/uploads/2007/03/windowslivewriterrefxmartinfowleronmodifiabilityqcon-d2cadsc-004600462.jpg" height="160" style="border-width: 0px" /></a> <a atomicselection="true" href="http://sadekdrobi.com/wp-content/uploads/2007/03/windowslivewriterrefxmartinfowleronmodifiabilityqcon-d2cadsc-0053005311.jpg"><img border="0" width="160" src="http://sadekdrobi.com/wp-content/uploads/2007/03/windowslivewriterrefxmartinfowleronmodifiabilityqcon-d2cadsc-005300532.jpg" height="240" style="border-width: 0px" /></a> <a atomicselection="true" href="http://sadekdrobi.com/wp-content/uploads/2007/03/windowslivewriterrefxmartinfowleronmodifiabilityqcon-d2cadsc-00370037-111.jpg"><img border="0" width="160" src="http://sadekdrobi.com/wp-content/uploads/2007/03/windowslivewriterrefxmartinfowleronmodifiabilityqcon-d2cadsc-00370037-12.jpg" height="240" style="border-width: 0px" /></a> <a atomicselection="true" href="http://sadekdrobi.com/wp-content/uploads/2007/03/windowslivewriterrefxmartinfowleronmodifiabilityqcon-d2cadsc-00510051-111.jpg"><img border="0" width="160" src="http://sadekdrobi.com/wp-content/uploads/2007/03/windowslivewriterrefxmartinfowleronmodifiabilityqcon-d2cadsc-00510051-12.jpg" height="240" style="border-width: 0px" /></a> <a atomicselection="true" href="http://sadekdrobi.com/wp-content/uploads/2007/03/windowslivewriterrefxmartinfowleronmodifiabilityqcon-d2cadsc-0052005211.jpg"><img border="0" width="240" src="http://sadekdrobi.com/wp-content/uploads/2007/03/windowslivewriterrefxmartinfowleronmodifiabilityqcon-d2cadsc-005200522.jpg" height="160" style="border-width: 0px" /></a> <a atomicselection="true" href="http://sadekdrobi.com/wp-content/uploads/2007/03/windowslivewriterrefxmartinfowleronmodifiabilityqcon-d2cadsc-00580058-111.jpg"><img border="0" width="240" src="http://sadekdrobi.com/wp-content/uploads/2007/03/windowslivewriterrefxmartinfowleronmodifiabilityqcon-d2cadsc-00580058-12.jpg" height="160" style="border-width: 0px" /></a> <a atomicselection="true" href="http://sadekdrobi.com/wp-content/uploads/2007/03/windowslivewriterrefxmartinfowleronmodifiabilityqcon-14440dsc-006700671.jpg"><img border="0" width="240" src="http://sadekdrobi.com/wp-content/uploads/2007/03/windowslivewriterrefxmartinfowleronmodifiabilityqcon-d2cadsc-00600060-12.jpg" height="160" style="border-width: 0px" /><img border="0" width="240" src="http://sadekdrobi.com/wp-content/uploads/2007/03/windowslivewriterrefxmartinfowleronmodifiabilityqcon-14440dsc-00670067.jpg" height="160" style="border: 0px" /> </a></p>
]]></content:encoded>
			<wfw:commentRss>http://sadekdrobi.com/2007/03/14/refx-martin-fowler-on-modifiability-qcon/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Obsev :: Implementing Domain Friendly, Predicates-like Specifications with C# 3.0 Expression trees</title>
		<link>http://sadekdrobi.com/2007/02/25/obsev-implementing-domain-friendly-predicates-like-specifications-with-c-30-expression-trees-2/</link>
		<comments>http://sadekdrobi.com/2007/02/25/obsev-implementing-domain-friendly-predicates-like-specifications-with-c-30-expression-trees-2/#comments</comments>
		<pubDate>Sun, 25 Feb 2007 21:54:18 +0000</pubDate>
		<dc:creator>Sadache</dc:creator>
				<category><![CDATA[Agile Programming]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Domain Driven Design]]></category>
		<category><![CDATA[Functional Programming]]></category>
		<category><![CDATA[Martin Fowler]]></category>

		<guid isPermaLink="false">http://sadekdrobi.com/?p=30</guid>
		<description><![CDATA[According to Fowler and Evans, Specification &#8221; is to separate the statement of how to match a candidate, from the candidate object that it is matched against. As well as its usefulness in selection, it is also valuable for validation and for building to order &#8220;Â  .
We might need to secify the state of an [...]]]></description>
			<content:encoded><![CDATA[<p>According to Fowler and Evans, Specification <a href="http://sadekdrobi.com/martinfowler.com/apsupp/spec.pdf">&#8221; is to separate the statement of how to match a candidate, from the candidate object that it is matched against. As well as its usefulness in selection, it is also valuable for validation and for building to order &#8220;</a>Â  .</p>
<p>We might need to secify the state of an object for one of these three purposes.</p>
<ul>
<li>To validate an object to see if it fullfills some need or ready for some purpose (Validation)</li>
<li>To select an object from a collection (Selection)</li>
<li>To specify the creation of a new object to fit some need (Building to order)Â  *Quote from DDD / Eric Evans*</li>
</ul>
<p><span id="more-30"></span></p>
<p>Specifications in the implementation of Fowler and Evans are classes, that contain the logic of validation, in a more explicit way than a methods that hides inside a domain object.</p>
<p>Composite specifications are specifications with logical operations like &#8220;And&#8221; &#8220;Or&#8221; defined to build a <em>composite</em> of exression tree. These operation can be presented in a more Domain friendly manner like a Â <em>fluent interface</em> where you can say for example Â </p>
<p><em>Spec1.And(Spec2).And(spec3.Not()) .</em></p>
<p><em /></p>
<p>The problem is that building such a composite , domain friendly , expression tree can add really a lot of classes to the application (Specifications Hirarchy, Expression Builders for having Fluent Interfaces,&#8230; etc) .</p>
<p>Those who have been arround microsoft technologies lately, might heard aboutÂ  Linq and C# 3.0, read some articles about it. Unfortunaitly Linq is often missunderstood, as embedding Sql in the code, which is DEFINITLY NOT THE CASE, Linq is all based on expression trees, that are intrepreted by an implementation engine for producing the appropriate query.</p>
<p>I will not go in details into Linq&#8217;s use for data quering, but i ll try to demonstrate another use of linq&#8217;s expression trees, in making explecit, predicate-like simple composite specifications.</p>
<p>For the purpose of the demo, i ll make a small introduction of some C# 3.0 features i am using.</p>
<p><strong>Extension Methods:</strong> Extension Methods are aÂ  syntaxic sugar, representing a special case of static methods to turn it more discoverable .</p>
<p>Example:</p>
<p><font color="#004080">public static class Extensions<br />
{Â Â Â  public static bool IsNullOrEmpty(this string s)<br />
Â Â Â  {<br />
Â Â Â Â Â Â Â  return (s == null || s.Trim().Length == 0 );<br />
Â Â Â  }<br />
} </font></p>
<p><font color="#004080">class Program<br />
{<br />
Â Â Â  static void Main( string[] args)<br />
Â Â Â  {<br />
Â Â Â Â Â Â Â  string newString = null;<br />
Â Â Â Â Â Â Â  if (newString.IsNullOrEmpty())<br />
Â Â Â Â Â Â Â  {<br />
Â Â Â Â Â Â Â Â Â Â Â  // Do Something<br />
Â Â Â Â Â Â Â  }<br />
Â Â Â  } </font></p>
<p><font color="#0080ff"><font color="#004080">}</font> </font></p>
<p>so the &#8220;this&#8221; keyword in the parameters tells that this will be an extension method for all the object of this type. dont worry , no encapsulation is violated, extension methods have access only to public members.</p>
<p><strong>Lambda Expressions:</strong> Lambda expression is a syntaxic sugar of the anonymous methods, for people that dont know delegates, delegates are method holders, u define a type of delegate by specifieng parameters and return types</p>
<p>like</p>
<p><font color="#0000a0">delegate object DelegateName(object par1,objaect par2); </font></p>
<p>then you can anonymously make a delegate like so</p>
<p><font color="#0000a0">DelegateName myDelegate= delegate(object par1,object par2){ </font></p>
<p><font color="#0000a0">Â Â Â  //do something here and return the delegates return type (object) </font></p>
<p><font color="#0000a0">Â Â Â  return new object(); </font></p>
<p><font color="#0000a0">}; </font></p>
<p>now u can call this delegate using its name mydelegate(obj1,obj2);</p>
<p>lambda expressions add even shorter syntax for defining the body of the anonymous method so u can for instance write</p>
<p><font color="#0000a0">DelegateName myDelegate= (object par1,object par2)Â  =&gt;Â  new object();</font></p>
<p>after this very brief introduction, i ll start implementing my very simple example of predicates:</p>
<p>first of all i ll define a delegate that will take a type T and returns a bool</p>
<p><font color="#0000a0">delegate bool ObjectPredicateDelegate&lt;T&gt;(T arg);</font></p>
<p>now i can write</p>
<p><font color="#0000a0">ObjectPredicateDelegate&lt;Student&gt; studentOver18= Student s =&gt; s.Age &gt; 18 ; </font></p>
<p>that defines an anonymous method that is compiled on compile time, so it can be executed using the name &#8220;studentOver18&#8243; and passing a student as a prameter, what i want is not method but an expression, lucky enough, Linq namespace has the Expression type so i can right</p>
<p><font color="#0000a0">Expression&lt;ObjectPredicateDelegate&lt;Student&gt;&gt; studentOver18Expression = Student s =&gt; s.Age &gt; 18 ; </font></p>
<p>you should be wondering whatÂ the deffirence is, this Epression is not compiled, it is deferred till the runtime, so id i want to execute it i should do</p>
<p><font color="#0000a0">studentOver18Expression.Compile().Invoke(s); </font></p>
<p>moreover <font color="#0000a0">studentOver18Expression.ToString()</font>Â  will produce &#8220;s =&gt; s.Age &gt;18&#8243; cool isnt it?</p>
<p>now, i want to implement And and Or operations that produce the same delegate , where i can pass a student and get a boolean. These operations are already implemented by default in Linq namespace, but they return a BooleanExpression which is not really what i want, so i ll do mine using Extension methods</p>
<p><font color="#0000a0">public static Expression&lt;ObjectPredicateDelegate&lt;Student&gt;&gt; And(this Expression&lt;ObjectPredicateDelegate&lt;Student&gt;&gt; exp1, Expression&lt;ObjectPredicateDelegate&lt;Student&gt;&gt; exp2){ </font></p>
<p><font color="#0000a0">Â Â Â Â  Â Â Â  Â Â Â  ParameterExpression p = Expression.Parameter(exp1.Parameters[0].Type, exp1.Parameters[0].Name);<br />
Â Â Â Â Â Â Â Â Â Â Â Â Â return (Expression&lt;ObjectPredicateDelegate&lt;Student&gt;&gt;)Expression.Lambda&lt;ObjectPredicateDelegate&lt;Student&gt;&gt;(<br />
Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  Expression.And(Expression.Invoke(exp1,p), Expression.Invoke(exp2,p)), p); </font></p>
<p><font color="#0000a0">} </font></p>
<p>now using this extension method i can write</p>
<p><font color="#0000a0">Expression&lt;ObjectPredicateDelegate&lt;Student&gt;&gt; studentOver18Specification = Student s =&gt; s.Age &gt; 18 ; </font></p>
<p><font color="#0000a0">Expression&lt;ObjectPredicateDelegate&lt;Student&gt;&gt; studentUnder26Specification = Student s =&gt; s.Age &lt; 26 ; </font></p>
<p><font color="#0000a0">Expression&lt;ObjectPredicateDelegate&lt;Student&gt;&gt; studentYouthAgeSpecification = studentOver18Specification.And(studentUnder26Specification); </font></p>
<p>now we can continue implementing other operations like Or, Not&#8230; in the same manner.</p>
<p>I agree that <font color="#0000a0">ObjectPredicateDelegate&lt;Student&gt;</font> is long to write each time , but we can use the &#8220;using&#8221; keyword to creat an alias</p>
<p><font color="#0000a0">using StudentPredicateDelegate=ObjectPredicateDelegate&lt;Student&gt;</font></p>
<p>or even</p>
<p><font color="#0000a0">using StudentPredicate=Expression&lt;ObjectPredicateDelegate&lt;Student&gt;&gt;</font></p>
<p>this way i can simplify the last code to look more friendly</p>
<p><font color="#0000a0">StudentPredicate studentOver18Specification = Student s =&gt; s.Age &gt; 18 ; </font></p>
<p><font color="#0000a0">StudentPredicate studentUnder26Specification = Student s =&gt; s.Age &lt; 26 ; </font></p>
<p><font color="#0000a0">StudentPredicate studentYouthAgeSpecification = studentOver18Specification.And(studentUnder26Specification); </font></p>
<p>now <font color="#0000a0">studentYouthAgeSpecification.ToString()</font>Â  will produceÂ Â Â Â  <font color="#008000">&#8220;s =&gt; (Invoke(s =&gt; (s.age &gt; 18),s) And Invoke(s =&gt; (s.age &lt; 26),s))&#8221; </font></p>
<p>i am not sure i ve been very clear, i ll try to post more examples soon :)</p>
<p><a id="p32" href="http://sadekdrobi.com/wp-content/uploads/2007/02/expressiontrees.zip">Download Sample Code Solution</a></p>
]]></content:encoded>
			<wfw:commentRss>http://sadekdrobi.com/2007/02/25/obsev-implementing-domain-friendly-predicates-like-specifications-with-c-30-expression-trees-2/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>OBSEV:: Fluent Interface and c# 3.0 Extension Methods : The flexibility of dynamic typing with the powerfull AutoCompletion</title>
		<link>http://sadekdrobi.com/2007/01/07/obsev-fluentinterface-and-c-30-extension-methods-the-flexibility-of-dynamic-typing-with-the-powerfull-autocompletion/</link>
		<comments>http://sadekdrobi.com/2007/01/07/obsev-fluentinterface-and-c-30-extension-methods-the-flexibility-of-dynamic-typing-with-the-powerfull-autocompletion/#comments</comments>
		<pubDate>Sun, 07 Jan 2007 23:12:29 +0000</pubDate>
		<dc:creator>Sadache</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Martin Fowler]]></category>

		<guid isPermaLink="false">http://sadekdrobi.com/?p=22</guid>
		<description><![CDATA[Fluent InterfaceÂ  is a pattern discovered by Eric Evans and Martin Fowler.
one problem of this pattern isÂ Â &#8221;a mismatch between what a fluent interface needs and our usual guidelines for API design. What works well for a regular API doesn&#8217;t work for a fluent one and vice versa .&#8221; (Fowler)
So using FluentInterface we start adding setters [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://martinfowler.com/bliki/FluentInterface.html" target="_blank">Fluent Interface</a>Â  is a pattern <em>discovered </em>by Eric Evans and Martin Fowler.</p>
<p>one problem of this pattern isÂ Â &#8221;<em>a mismatch between what a fluent interface needs and our usual guidelines for API design. What works well for a regular API doesn&#8217;t work for a fluent one and vice versa .&#8221; (Fowler)</em></p>
<p>So using FluentInterface we start adding setters that have a return value, others that they should not belong to the class in the API terms, but they do in Dsl terms.</p>
<p>Martin suggested an Expression Builder, which is a class that contains these bizar methods, But that means more classes, moreover, returning an interface of that <em>Expression Builder </em>that only contains allowed methods will add even more files and interfaces!</p>
<p>then He stated <em>&#8220;dynamic languages work better for DSLs since they tend to have <span id="more-22"></span>a less cluttered syntax. Using method completion, however, is a plus for static languages.&#8221;</em></p>
<p>Now if u ve been following c# news about the future version, then you absolutely heard of Extension Methods.</p>
<p>Extension methods are nothing but syntactic sugar, they are actuelly static methods that operate on a specific class, the following example illustraits better:</p>
<p><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> Extensions<br />
{</span><span style="color: #000000"><span style="color: #000000">Â Â Â  </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span style="color: #0000ff">bool</span><span style="color: #000000"> IsNullOrEmpty(</span><span style="color: #0000ff">this</span><span style="color: #000000"> </span><span style="color: #0000ff">string</span><span style="color: #000000"> s)<br />
Â Â Â  {<br />
Â Â Â Â Â Â Â  </span><span style="color: #008000">//</span><span style="color: #008000"> Notice I trim it too :)</span><span style="color: #008000"><br />
</span><span style="color: #000000">Â Â Â Â Â Â Â  </span><span style="color: #0000ff">return</span><span style="color: #000000"> (s </span><span style="color: #000000">==</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000"> </span><span style="color: #000000">||</span><span style="color: #000000"> s.Trim().Length </span><span style="color: #000000">==</span><span style="color: #000000"> </span><span style="color: #ff0000">0</span><span style="color: #000000">);<br />
Â Â Â  }<br />
}</span></span><span style="color: #000000"><span style="color: #0000ff">class</span><span style="color: #000000"> Program<br />
{<br />
Â Â Â  </span><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> Main(</span><span style="color: #0000ff">string</span><span style="color: #000000">[] args)<br />
Â Â Â  {<br />
Â Â Â Â Â Â Â  </span><span style="color: #0000ff">string</span><span style="color: #000000"> newString </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000">;<br />
Â Â Â Â Â Â Â  </span><span style="color: #0000ff">if</span><span style="color: #000000"> (newString.IsNullOrEmpty())<br />
Â Â Â Â Â Â Â  {<br />
Â Â Â Â Â Â Â Â Â Â Â  </span><span style="color: #008000">//</span><span style="color: #008000"> Do Something</span><span style="color: #008000"><br />
</span><span style="color: #000000">Â Â Â Â Â Â Â  }<br />
Â Â Â  }<br />
}</span></span><span style="color: #000000"><span style="color: #000000">so the compiler will turn this into a normal call of a static method so it will be </span></span><span style="color: #000000"><span style="color: #000000">Extensions.IsNullOrEmpty(newString) </span></span><span style="color: #000000"><span style="color: #000000">that helps to semplify the readibility of the code , and autoCompletion. But i agree that it is a dangerous feature and should be used with attention.</span></span><span style="color: #000000"><span style="color: #000000">Extension Methods will sit in classes in a namespace, that once u included, u can apply use them autoCompletion.</span></span><span style="color: #000000"><span style="color: #000000">Now the question is : Why do i relate this to the fluentInterface, i ll try to illustrate using to scinarios what can it bring to this pattern.</span></p>
<p></span><span style="color: #000000">The first problem i talked about is returning the type when using a setter, that can be easily avoided by using extension methods. So that in the Class there are normal setters, but when u import the namespace using &#8220;using&#8221; keyword , you get AutoCompletion on the Weired Dsl friendly ,fluent interface&#8217;s this returning value setters :)</span></p>
<p><span style="color: #000000"><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> ExpressionBuilder<br />
{</span></span><span style="color: #000000"><span style="color: #000000"><span style="color: #000000">Â Â Â  </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> Order </span><span style="color: #000000">With(</span><span style="color: #0000ff">this</span><span style="color: #000000">Â Order o,int id,string orderLine</span><span style="color: #0000ff">Â </span><span style="color: #000000">)<br />
Â Â Â  {<br />
Â Â Â Â Â Â Â o.AddLine(<span style="color: #0000ff">new</span><span style="color: #000000"> </span>OrderLine(id,orderLine))</span><span style="color: #008000"><br />
</span><span style="color: #000000">Â Â Â Â Â Â Â  </span><span style="color: #0000ff">return</span><span style="color: #000000">Â o;</span><span style="color: #000000"><br />
Â Â Â  }</span></span></span><span style="color: #000000"><span style="color: #000000"><span style="color: #000000">Â Â Â  <span style="color: #0000ff"><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> Order </span><span style="color: #000000">PriorityRush(</span><span style="color: #0000ff">this</span><span style="color: #000000">Â Order o</span><span style="color: #0000ff">Â </span><span style="color: #000000">)<br />
Â Â Â  {<br />
Â Â Â Â Â Â Â o.SetRush(<span style="color: #0000ff">true</span>);</span><span style="color: #008000"><br />
</span><span style="color: #000000">Â Â Â Â Â Â Â  </span><span style="color: #0000ff">return</span><span style="color: #000000">Â o;</span><span style="color: #000000"><br />
Â Â Â  }</span></span></span><span style="color: #000000"><span style="color: #000000" /></span></span></span><span style="color: #000000"><span style="color: #000000"><span style="color: #000000">Â Â Â  </span></span></span><span style="color: #000000"><span style="color: #000000"><span style="color: #000000"><br />
}</span></span></span><span style="color: #000000"><span style="color: #000000"><span style="color: #0000ff">class</span><span style="color: #000000"> Program<br />
{<br />
Â Â Â  </span><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> Main(</span><span style="color: #0000ff">string</span><span style="color: #000000">[] args)<br />
Â Â Â  {<br />
Â Â Â Â Â Â Â Â Order o1= new Order();<br />
Â Â Â Â Â Â Â  o1.With(6, &#8220;TAL&#8221;)<br />
Â Â Â Â Â Â Â Â Â Â Â Â .With(5, &#8220;HPK&#8221;).skippable()<br />
Â Â Â Â Â Â Â Â Â Â Â Â .With(3, &#8220;LGV&#8221;)<br />
Â Â Â Â Â Â Â Â Â Â Â Â .PriorityRush();<br />
</span></span></span><span style="color: #000000"><span style="color: #000000"><span style="color: #000000" /><span style="color: #000000">Â Â Â  }<br />
}</span></span></span><span style="color: #000000"><span style="color: #000000"><span style="color: #000000">Here we can agree on somehting, the auto completion help without the need of knowing about another class which is the expression helper. But still the title says Dunamic? where is it?</span></p>
<p></span><span style="color: #000000">ok that is my second scenario, the previous code looks really handy, but still i need to implement the moethds for each class, that is where the power of Generics and Reflection comes to the scene!</span></p>
<p><span style="color: #000000">so what about an ExpressionBuilder where t:IFluentable</span></p>
<p><span style="color: #000000">then the ExtensionMethods will be applicable to any Type that implements IFluentable, and will return their types!</span></p>
<p><span style="color: #000000">but here, we still have to implement interfaces, and we cant have an IFluentable that works for all expression builder, what can we ease and facilate here isÂ general cases,Â a very good example of such a generic fluent interface isÂ Linq project , which works in IQuerable and IEnumerable, which will also be released in c# 3.0.</span></p>
<p><span style="color: #000000" />furthermore, reflection can beÂ used inside the extension methods to discover properties that belong toÂ the concrete class, and not only the interface.</p>
<p>i suggest reading about the Linq project, it is quite interesting good implementation of a Dsl language that is both, API andÂ FluentInterface Friendly.</p>
<p><a href="http://msdn2.microsoft.com/en-us/vcsharp/aa336746.aspx">http://msdn2.microsoft.com/en-us/vcsharp/aa336746.aspx</a></p>
<p>Â PS: There will be no need to specify the Types to the generic class and methods, thanks to <a href="http://blogs.msdn.com/ericlippert/archive/2006/11/17/a-face-made-for-email-part-three.aspx" target="_blank">Generics Type Inference</a> thatÂ went well far in the C# 3.0 compiler!</p>
<p>you can already downloadÂ aÂ CTP (Demo) compilerÂ ofÂ LINQ (including c# 3.0) from <a href="http://www.microsoft.com/downloads/details.aspx?familyid=1e902c21-340c-4d13-9f04-70eb5e3dceea&#038;displaylang=en">http://www.microsoft.com/downloads/details.aspx?familyid=1e902c21-340c-4d13-9f04-70eb5e3dceea&#038;displaylang=en</a><br />
Â </p>
<p>Â </p>
<p>Â </p>
<p>Â </p>
<p /></span></p>
]]></content:encoded>
			<wfw:commentRss>http://sadekdrobi.com/2007/01/07/obsev-fluentinterface-and-c-30-extension-methods-the-flexibility-of-dynamic-typing-with-the-powerfull-autocompletion/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

