<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;DEUMQX4_cSp7ImA9WhRaFEk.&quot;"><id>tag:blogger.com,1999:blog-7331742083114938114</id><updated>2012-02-17T05:38:00.049+03:00</updated><category term="C#" /><category term="design pattern" /><category term="LINQ" /><category term="MVC" /><category term="Database" /><category term="Lambda" /><category term="ORM" /><category term="singleton" /><category term="DRY" /><category term="OO Design" /><category term="XML" /><category term="Expression-Trees" /><category term="DAL" /><category term=".NET" /><category term="ASP.NET" /><title>My Computing Life</title><subtitle type="html">Things I have interested...or I walk through
Blog on
.Net,OOD ,SOA,Database, ...etc</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://tadeze.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://tadeze.blogspot.com/" /><author><name>tadesse</name><uri>http://www.blogger.com/profile/01745642569109272755</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>8</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/MyComputingLife" /><feedburner:info uri="mycomputinglife" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry gd:etag="W/&quot;AkQDQn4-fip7ImA9WhdTF00.&quot;"><id>tag:blogger.com,1999:blog-7331742083114938114.post-6589500895050923551</id><published>2011-07-15T08:07:00.000+03:00</published><updated>2011-07-15T08:39:33.056+03:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-15T08:39:33.056+03:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Expression-Trees" /><category scheme="http://www.blogger.com/atom/ns#" term="DAL" /><category scheme="http://www.blogger.com/atom/ns#" term="Lambda" /><category scheme="http://www.blogger.com/atom/ns#" term="LINQ" /><title>Explaining the vague of Expression Trees</title><content type="html">&lt;b style=""&gt;&lt;span style="font-size: 14pt; line-height: 115%; color: rgb(227, 108, 10);"&gt;Introduction&lt;/span&gt;&lt;/b&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; line-height: 115%;"&gt;Expression trees are mainly used to generate query at run time. Expression trees represent the whole lambda expression.&lt;span style=""&gt;  &lt;/span&gt;Combined with generics expression trees provide an important code re-usability for the project.&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; line-height: 115%;"&gt;When I was reading a book about LINQ, which is LINQ in action.&lt;span style=""&gt;  &lt;/span&gt;I find difficulty on understanding about the expression trees. Even I though what is their importance?&lt;span style=""&gt;  &lt;/span&gt;Where do we use Expression trees? I searched for the SO for question if they are already asked; even I find a triple of question which related to question. But still I didn’t convince totally where the expression trees fit in an application.&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; line-height: 115%;"&gt;Luckily, I come to the need of them and I come up to share my lucky experience for the readers. &lt;span style=""&gt; &lt;/span&gt;When I was developing for my project, I come to the need of quick search capability by its primary key in each data entry form. Before that I had completed designing the Generic repository for all of my data access layer entity using LINQ to SQL. However rather than the conventional repository method I developed with the generics which accepts a functor expression i.e.&lt;span style=""&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 12pt; color: blue;"&gt;Public&lt;/span&gt;&lt;span style="font-size: 12pt;"&gt; &lt;span style="color: blue;"&gt;Function&lt;/span&gt; Find(&lt;span style="color: blue;"&gt;ByVal&lt;/span&gt; where &lt;span style="color: blue;"&gt;As&lt;/span&gt; System.Func(&lt;span style="color: blue;"&gt;Of&lt;/span&gt; T, &lt;span style="color: blue;"&gt;Boolean&lt;/span&gt;)) &lt;span style="color: blue;"&gt;As&lt;/span&gt; System.Collections.Generic.IEnumerable(&lt;span style="color: blue;"&gt;Of&lt;/span&gt; T) &lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 12pt; color: blue;"&gt;Implements &lt;/span&gt;&lt;span style="font-size: 12pt;"&gt;&lt;span style=""&gt; &lt;/span&gt;IRepository(&lt;span style="color: blue;"&gt;Of&lt;/span&gt; T).Find&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 12pt;"&gt; &lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 12pt;"&gt;&lt;span style=""&gt; &lt;/span&gt;&lt;span style="color: blue;"&gt;Return&lt;/span&gt; repository.GetTable(&lt;span style="color: blue;"&gt;Of&lt;/span&gt; T).Where(where)&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; line-height: 115%;"&gt;&lt;span style=""&gt; &lt;/span&gt;&lt;span style="color: blue;"&gt;End&lt;/span&gt; &lt;span style="color: blue;"&gt;Function&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; line-height: 115%;"&gt;I want a generic search method which receives an Id as an argument and finds the particular entity cross ponding with the Id where the entity type is defined at runtime. When I dig up for various methods and techniques I couldn’t find to my help. Finally the expression trees come to the rescue.&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 12pt; color: blue;"&gt;Public&lt;/span&gt;&lt;span style="font-size: 12pt;"&gt; &lt;span style="color: blue;"&gt;Function&lt;/span&gt; SearchbyId(&lt;span style="color: blue;"&gt;ByVal&lt;/span&gt; id &lt;span style="color: blue;"&gt;As&lt;/span&gt; &lt;span style="color: blue;"&gt;Integer&lt;/span&gt;) &lt;span style="color: blue;"&gt;As&lt;/span&gt; T&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 12pt; color: blue;"&gt; &lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 12pt; color: blue;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 12pt;"&gt; entity = Expression.Parameter(&lt;span style="color: blue;"&gt;GetType&lt;/span&gt;(T),&lt;span style="color: rgb(163, 21, 21);"&gt;entity"&lt;/span&gt;)&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 12pt;"&gt;&lt;span style=""&gt; &lt;/span&gt;&lt;span style="color: blue;"&gt;Dim&lt;/span&gt; whereexpr = Expression.Lambda(&lt;span style="color: blue;"&gt;Of&lt;/span&gt; Func(&lt;span style="color: blue;"&gt;Of&lt;/span&gt; T, &lt;span style="color: blue;"&gt;Boolean&lt;/span&gt;))( _&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 12pt;"&gt;&lt;span style=""&gt;        &lt;/span&gt;Expression.Equal(Expression.Property(entity, &lt;span style="color: rgb(163, 21, 21);"&gt;"Id"&lt;/span&gt;), _&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 12pt;"&gt;&lt;span style=""&gt; &lt;/span&gt;Expression.Constant(id)), &lt;span style="color: blue;"&gt;New&lt;/span&gt; ParameterExpression() {entity})&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 12pt;"&gt;&lt;span style=""&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 12pt; color: blue;"&gt;Return&lt;/span&gt;&lt;span style="font-size: 12pt;"&gt; SingleorDefault(whereexpr.Compile())&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; line-height: 115%;"&gt;&lt;span style=""&gt; &lt;/span&gt;&lt;span style="color: blue;"&gt;End&lt;/span&gt; &lt;span style="color: blue;"&gt;Function&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; line-height: 115%; color: blue;"&gt; &lt;/span&gt;&lt;/p&gt;  &lt;ul&gt;&lt;li&gt;&lt;span style="font-size: 12pt; font-family: Symbol;"&gt;&lt;span style=""&gt;·&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;         &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 12pt;"&gt;Expression.Equal(Expression.Property(entity, &lt;span style="color: rgb(163, 21, 21);"&gt;"Id"&lt;/span&gt;), Expression.Constant(id)) – This represents the actual expression equality of the passed Id with entity id which is the primary key.&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;  &lt;ul&gt;&lt;li&gt;&lt;span style="font-size: 12pt; line-height: 115%; font-family: Symbol;"&gt;&lt;span style=""&gt;·&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;         &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 12pt; line-height: 115%;"&gt;Expression.Lambda(--------) : This converts into lambda expression when the expression is compiled at runtime with the compile method i.e whereexpr.compile()&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; line-height: 115%;"&gt;This method assumes you have named all your tables’ primary key as “ID” so that every time the method is called it compares the passed value with Id.&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;b style=""&gt;&lt;span style="font-size: 14pt; line-height: 115%; color: rgb(227, 108, 10);"&gt;Conclusion&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; line-height: 115%;"&gt;An expression tree builds a lambda expression with its various methods and property at runtime. &lt;/span&gt;So when you come to the need of building query at runtime the solution is to use expression trees. for its full description of its property and methods MSDN is you mentor for now lets us recap with MSDN illustration of Expression trees.&lt;span style="font-size: 12pt; line-height: 115%;"&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 3.75pt; line-height: normal;"&gt;&lt;span style="font-size: 12pt; color: black;"&gt;Expression trees represent language-level code in the form of data. The data is stored in a tree-shaped structure. Each node in the expression tree represents an expression, for example a method call or a binary operation such as &lt;/span&gt;&lt;span style="font-size: 12pt; color: rgb(0, 0, 102);"&gt;x &amp;lt; y&lt;/span&gt;&lt;span style="font-size: 12pt; color: black;"&gt;. The following illustration shows an example of an expression and its representation in the form of an expression tree. The different parts of the expression are color coded to match the corresponding expression tree node in the expression tree. The different types of the expression tree nodes are also shown.&lt;/span&gt;&lt;/p&gt; &lt;br /&gt;&lt;br /&gt;&lt;!--[if !mso]&gt; &lt;style&gt; v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VML);} .shape {behavior:url(#default#VML);} &lt;/style&gt; &lt;![endif]--&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;o:officedocumentsettings&gt;   &lt;o:allowpng/&gt;   &lt;o:targetscreensize&gt;1024x768&lt;/o:TargetScreenSize&gt;  &lt;/o:OfficeDocumentSettings&gt; &lt;/xml&gt;&lt;![endif]--&gt;&amp;lt;!--[if gte mso 9]&amp;gt;&lt;xml&gt;  &lt;w:worddocument&gt;   &lt;w:view&gt;Normal&lt;/w:view&gt;   &lt;w:zoom&gt;0&lt;/w:zoom&gt;   &lt;w:trackmoves&gt;   &lt;w:trackformatting&gt;   &lt;w:punctuationkerning&gt;   &lt;w:validateagainstschemas&gt;   &lt;w:saveifxmlinvalid&gt;false&lt;/w:saveifxmlinvalid&gt;   &lt;w:ignoremixedcontent&gt;false&lt;/w:ignoremixedcontent&gt;   &lt;w:alwaysshowplaceholdertext&gt;false&lt;/w:alwaysshowplaceholdertext&gt;   &lt;w:donotpromoteqf&gt;   &lt;w:lidthemeother&gt;EN-US&lt;/w:lidthemeother&gt;   &lt;w:lidthemeasian&gt;X-NONE&lt;/w:lidthemeasian&gt;   &lt;w:lidthemecomplexscript&gt;X-NONE&lt;/w:lidthemecomplexscript&gt;   &lt;w:compatibility&gt;    &lt;w:breakwrappedtables&gt;    &lt;w:snaptogridincell&gt;    &lt;w:wraptextwithpunct&gt;    &lt;w:useasianbreakrules&gt;    &lt;w:dontgrowautofit&gt;    &lt;w:splitpgbreakandparamark&gt;    &lt;w:dontvertaligncellwithsp&gt;    &lt;w:dontbreakconstrainedforcedtables&gt;    &lt;w:dontvertalignintxbx&gt;    &lt;w:word11kerningpairs&gt;    &lt;w:cachedcolbalance&gt;   &lt;/w:cachedcolbalance&gt;   &lt;m:mathpr&gt;    &lt;m:mathfont val="Cambria Math"&gt;    &lt;m:brkbin val="before"&gt;    &lt;m:brkbinsub val=""&gt;    &lt;m:smallfrac val="off"&gt;    &lt;m:dispdef&gt;    &lt;m:lmargin val="0"&gt;    &lt;m:rmargin val="0"&gt;    &lt;m:defjc val="centerGroup"&gt;    &lt;m:wrapindent val="1440"&gt;    &lt;m:intlim val="subSup"&gt;    &lt;m:narylim val="undOvr"&gt;   &lt;/m:narylim&gt;&lt;/m:intlim&gt; &lt;/m:wrapindent&gt;&lt;!--[endif]--&gt;&lt;!----&gt;&lt;span style="font-size:12pt;"&gt; &lt;/span&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/-xyWCVshhQwk/Th_P-DaKfnI/AAAAAAAAAGk/gh738Ne10QY/s1600/expressiontree.JPG"&gt;&lt;img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 458px; height: 254px;" src="http://4.bp.blogspot.com/-xyWCVshhQwk/Th_P-DaKfnI/AAAAAAAAAGk/gh738Ne10QY/s320/expressiontree.JPG" alt="" id="BLOGGER_PHOTO_ID_5629446724210294386" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:12pt;"&gt; &lt;/span&gt;&lt;xml&gt;&lt;w:latentstyles deflockedstate="false" defunhidewhenused="true" defsemihidden="true" defqformat="false" defpriority="99" latentstylecount="267"&gt;&lt;w:lsdexception locked="false" priority="0" semihidden="false" unhidewhenused="false" qformat="true" name="Normal"&gt;&lt;w:lsdexception locked="false" priority="9" semihidden="false" unhidewhenused="false" qformat="true" name="heading 1"&gt;&lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 2"&gt;&lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 3"&gt;&lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 4"&gt;&lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 5"&gt;&lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 6"&gt;&lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 7"&gt;&lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 8"&gt;&lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 9"&gt;&lt;w:lsdexception locked="false" priority="39" name="toc 1"&gt;&lt;w:lsdexception locked="false" priority="39" name="toc 2"&gt;&lt;w:lsdexception locked="false" priority="39" name="toc 3"&gt;&lt;w:lsdexception locked="false" priority="39" name="toc 4"&gt;&lt;w:lsdexception locked="false" priority="39" name="toc 5"&gt;&lt;w:lsdexception locked="false" priority="39" name="toc 6"&gt;&lt;w:lsdexception locked="false" priority="39" name="toc 7"&gt;&lt;w:lsdexception locked="false" priority="39" name="toc 8"&gt;&lt;w:lsdexception locked="false" priority="39" name="toc 9"&gt;&lt;w:lsdexception locked="false" priority="35" qformat="true" name="caption"&gt;&lt;w:lsdexception locked="false" priority="10" semihidden="false" unhidewhenused="false" qformat="true" name="Title"&gt;&lt;w:lsdexception locked="false" priority="1" name="Default Paragraph Font"&gt;&lt;w:lsdexception locked="false" priority="11" semihidden="false" unhidewhenused="false" qformat="true" name="Subtitle"&gt;&lt;w:lsdexception locked="false" priority="22" semihidden="false" unhidewhenused="false" qformat="true" name="Strong"&gt;&lt;w:lsdexception locked="false" priority="20" semihidden="false" unhidewhenused="false" qformat="true" name="Emphasis"&gt;&lt;w:lsdexception locked="false" priority="59" semihidden="false" unhidewhenused="false" name="Table Grid"&gt;&lt;w:lsdexception locked="false" unhidewhenused="false" name="Placeholder Text"&gt;&lt;w:lsdexception locked="false" priority="1" semihidden="false" unhidewhenused="false" qformat="true" name="No Spacing"&gt;&lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading"&gt;&lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List"&gt;&lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid"&gt;&lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1"&gt;&lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2"&gt;&lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1"&gt;&lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2"&gt;&lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1"&gt;&lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2"&gt;&lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3"&gt;&lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List"&gt;&lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading"&gt;&lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List"&gt;&lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid"&gt;&lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 1"&gt;&lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 1"&gt;&lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 1"&gt;&lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 1"&gt;&lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 1"&gt;&lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 1"&gt;&lt;w:lsdexception locked="false" unhidewhenused="false" name="Revision"&gt;&lt;w:lsdexception locked="false" priority="34" semihidden="false" unhidewhenused="false" qformat="true" name="List Paragraph"&gt;&lt;w:lsdexception locked="false" priority="29" semihidden="false" unhidewhenused="false" qformat="true" name="Quote"&gt;&lt;w:lsdexception locked="false" priority="30" semihidden="false" unhidewhenused="false" qformat="true" name="Intense Quote"&gt;&lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 1"&gt;&lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 1"&gt;&lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 1"&gt;&lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 1"&gt;&lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 1"&gt;&lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 1"&gt;&lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 1"&gt;&lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 1"&gt;&lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 2"&gt;&lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 2"&gt;&lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 2"&gt;&lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 2"&gt;&lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 2"&gt;&lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 2"&gt;&lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 2"&gt;&lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 2"&gt;&lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 2"&gt;&lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 2"&gt;&lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 2"&gt;&lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 2"&gt;&lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 2"&gt;&lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 2"&gt;&lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 3"&gt;&lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 3"&gt;&lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 3"&gt;&lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 3"&gt;&lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 3"&gt;&lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 3"&gt;&lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 3"&gt;&lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 3"&gt;&lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 3"&gt;&lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 3"&gt;&lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 3"&gt;&lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 3"&gt;&lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 3"&gt;&lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 3"&gt;&lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 4"&gt;&lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 4"&gt;&lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 4"&gt;&lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 4"&gt;&lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 4"&gt;&lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 4"&gt;&lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 4"&gt;&lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 4"&gt;&lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 4"&gt;&lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 4"&gt;&lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 4"&gt;&lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 4"&gt;&lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 4"&gt;&lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 4"&gt;&lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 5"&gt;&lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 5"&gt;&lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 5"&gt;&lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 5"&gt;&lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 5"&gt;&lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 5"&gt;&lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 5"&gt;&lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 5"&gt;&lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 5"&gt;&lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 5"&gt;&lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 5"&gt;&lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 5"&gt;&lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 5"&gt;&lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 5"&gt;&lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 6"&gt;&lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 6"&gt;&lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 6"&gt;&lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 6"&gt;&lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 6"&gt;&lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 6"&gt;&lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 6"&gt;&lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 6"&gt;&lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 6"&gt;&lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 6"&gt;&lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 6"&gt;&lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 6"&gt;&lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 6"&gt;&lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 6"&gt;&lt;w:lsdexception locked="false" priority="19" semihidden="false" unhidewhenused="false" qformat="true" name="Subtle Emphasis"&gt;&lt;w:lsdexception locked="false" priority="21" semihidden="false" unhidewhenused="false" qformat="true" name="Intense Emphasis"&gt;&lt;w:lsdexception locked="false" priority="31" semihidden="false" unhidewhenused="false" qformat="true" name="Subtle Reference"&gt;&lt;w:lsdexception locked="false" priority="32" semihidden="false" unhidewhenused="false" qformat="true" name="Intense Reference"&gt;&lt;w:lsdexception locked="false" priority="33" semihidden="false" unhidewhenused="false" qformat="true" name="Book Title"&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:lsdexception&gt;&lt;/w:latentstyles&gt;&lt;/xml&gt;&lt;/m:defjc&gt;&lt;/m:rmargin&gt;&lt;/m:lmargin&gt;&lt;/m:dispdef&gt;&lt;/m:smallfrac&gt;&lt;/m:brkbinsub&gt;&lt;/m:brkbin&gt;&lt;/m:mathfont&gt;&lt;/m:mathpr&gt;&lt;/w:word11kerningpairs&gt;&lt;/w:dontvertalignintxbx&gt;&lt;/w:dontbreakconstrainedforcedtables&gt;&lt;/w:dontvertaligncellwithsp&gt;&lt;/w:splitpgbreakandparamark&gt;&lt;/w:dontgrowautofit&gt;&lt;/w:useasianbreakrules&gt;&lt;/w:wraptextwithpunct&gt;&lt;/w:snaptogridincell&gt;&lt;/w:breakwrappedtables&gt;&lt;/w:compatibility&gt;&lt;/w:donotpromoteqf&gt;&lt;/w:validateagainstschemas&gt;&lt;/w:punctuationkerning&gt;&lt;/w:trackformatting&gt;&lt;/w:trackmoves&gt;&lt;/w:worddocument&gt;&lt;/xml&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7331742083114938114-6589500895050923551?l=tadeze.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/QTg5W39OXK0rPZn_YHU77W_bIXw/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/QTg5W39OXK0rPZn_YHU77W_bIXw/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/QTg5W39OXK0rPZn_YHU77W_bIXw/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/QTg5W39OXK0rPZn_YHU77W_bIXw/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MyComputingLife/~4/cOeVQm1tBSU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://tadeze.blogspot.com/feeds/6589500895050923551/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=7331742083114938114&amp;postID=6589500895050923551" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7331742083114938114/posts/default/6589500895050923551?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7331742083114938114/posts/default/6589500895050923551?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MyComputingLife/~3/cOeVQm1tBSU/explaining-vague-of-expression-trees.html" title="Explaining the vague of Expression Trees" /><author><name>tadesse</name><uri>http://www.blogger.com/profile/01745642569109272755</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-xyWCVshhQwk/Th_P-DaKfnI/AAAAAAAAAGk/gh738Ne10QY/s72-c/expressiontree.JPG" height="72" width="72" /><thr:total>1</thr:total><feedburner:origLink>http://tadeze.blogspot.com/2011/07/explaining-vague-of-expression-trees.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D04BQ3w_eCp7ImA9Wx9QFE4.&quot;"><id>tag:blogger.com,1999:blog-7331742083114938114.post-7555161371268453839</id><published>2010-12-27T09:56:00.002+03:00</published><updated>2010-12-27T10:45:52.240+03:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-12-27T10:45:52.240+03:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="MVC" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET" /><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET" /><title>My first test to ASP.NET MVC framework</title><content type="html">This week I started to read a book about the new Microsoft new web development implementation MVC framework. When I started to read about the framework, I really like the test of the MVC framework.&lt;br /&gt;My first intention was to just to skim at the technology, however once I started to read a Book &lt;a href="http://apress.com/book/view/9781430210078"&gt;&lt;br /&gt;Pro. ASP.NET MVC, Apress publisher by Steven Sanderson&lt;/a&gt;, the book grabbed me and I cannot leave it out. Now I think the book is in its second edition.&lt;br /&gt;The author of the book Sanderson has done great job at explaining the thing with very interesting and attracting small application. Although I couldn’t found the book I read about 4 chapters from an eBook and it really impress me.&lt;br /&gt;The second thing is I was astonished by the way Microsoft designing the framework. I mean although the technology have been quite active by other vendors such java, Ruby for a while, I though it contradicts the idea of web forms. In MVC technology you did a lot of thing using hardcoding and in addition you have a lot of control over the html controls which web forms lucks.&lt;br /&gt;When I was in college I have played a long time with PHP, one thing I like and hate about PHP was I did a lot of code to simply display a grid page with paging from database. In one side I feel confident and excited about the control I have over the html tags, CSS and the understanding about the inner working of the page. This gives a lot processing to be done before coding in my mind and that is the excitement of programming. In the other side when I look for production, the same grid page can be done in just two minutes using ASP.NET web forms.&lt;br /&gt;In the past few years we have been played using ASP.NET web forms after the classic ASP. The good side of the web form is rapid application, however the control over the page have been claimed by many developers. Now Microsoft released their MVC framework now in its version 2. With the MVC I have now the control on page where I lost in web forms. In addition many features of the web form are not used in this platform. The major emphasis was scalability and it has clean separation of layers. The separation of layers and test driven development (TDD) is one of its cool features. Routing also provide a clear web page URL as well as good management over the View layer.&lt;br /&gt;In addition, the request response mechanism has a little bit difference from the past. The controller and view plays a major role here, I really like the idea of controllers they receive request and respond it with its corresponding view.&lt;br /&gt;Finally I would like you to test hello world using ASP.NET MVC. Here the operation done using controller and view since we didn’t have any valid Model.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;//Controller class&lt;br /&gt;Using System.web.Mvc;&lt;br /&gt;Public class HelloworldController:controller&lt;br /&gt;{&lt;br /&gt;public ViewResult HelloWorl()&lt;br /&gt;{//where the View (viewname,model name)&lt;br /&gt;&lt;br /&gt;ViewData[“Hw”]=”Hello world from ASP.NET MVC”;&lt;br /&gt;return View(“helloW”);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;//View&lt;br /&gt;//Our view may look like this, when designing the view I assume we are using the master page&lt;br /&gt;//helloW.aspx&lt;br /&gt;&lt;%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage&lt;dynamic&gt;" %&gt;&lt;br /&gt;&lt;asp:content id="Content1" contentplaceholderid="TitleContent" runat="server"&gt;&lt;br /&gt;HelloWorld&lt;br /&gt;&lt;/asp:Content&gt;&lt;br /&gt;&lt;asp:content id="Content2" contentplaceholderid="MainContent" runat="server"&gt;&lt;br /&gt;&lt;h2&gt;HelloWorld&lt;/h2&gt;&lt;br /&gt;&lt;% =ViewData["Hw"] //reference using the ViewData name index %&gt;&lt;br /&gt;&lt;/asp:Content&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;The example just an illustration what it looks like it just displays “hello world from ASP.NET” it is our hello world example, even more illustrated Visual studio creates a template for sample hello world with its entire layer separated.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7331742083114938114-7555161371268453839?l=tadeze.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/O6vBWWTk-OX6su9RRN5pnieSe90/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/O6vBWWTk-OX6su9RRN5pnieSe90/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/O6vBWWTk-OX6su9RRN5pnieSe90/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/O6vBWWTk-OX6su9RRN5pnieSe90/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MyComputingLife/~4/EEdhZOL90zY" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://tadeze.blogspot.com/feeds/7555161371268453839/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=7331742083114938114&amp;postID=7555161371268453839" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7331742083114938114/posts/default/7555161371268453839?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7331742083114938114/posts/default/7555161371268453839?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MyComputingLife/~3/EEdhZOL90zY/my-first-test-to-aspnet-mvc-framework.html" title="My first test to ASP.NET MVC framework" /><author><name>tadesse</name><uri>http://www.blogger.com/profile/01745642569109272755</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://tadeze.blogspot.com/2010/12/my-first-test-to-aspnet-mvc-framework.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkcNR3czcSp7ImA9Wx9RGUw.&quot;"><id>tag:blogger.com,1999:blog-7331742083114938114.post-6146904742804187164</id><published>2010-12-21T08:27:00.000+03:00</published><updated>2010-12-21T08:41:36.989+03:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-12-21T08:41:36.989+03:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Database" /><category scheme="http://www.blogger.com/atom/ns#" term="XML" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="LINQ" /><category scheme="http://www.blogger.com/atom/ns#" term="ORM" /><title>Simplified XML Based Phone Book Database using LINQ</title><content type="html">&lt;img src="file:///C:/DOCUME%7E1/star7/LOCALS%7E1/Temp/moz-screenshot-1.jpg" alt="" /&gt;&lt;img src="file:///C:/DOCUME%7E1/star7/LOCALS%7E1/Temp/moz-screenshot-2.jpg" alt="" /&gt;&lt;h2 style="color: rgb(255, 153, 0);"&gt;Introduction&lt;/h2&gt;  &lt;p&gt;One day I was thinking how ADO .NET utilizes the database accessibility using dataset and ORM tools. One thing that impresses me was the power of XML technology. Using a plain XML, we can use almost all features of relational database (thanks to their inventor). Even the introduction of XML changed the way programs are build, the structure of configuration files, etc. In .NET, the &lt;code&gt;dataset &lt;/code&gt;class can read and write its temporary data to XML. When I was planning to develop a small application using these features, I thought of developing the application using ORM operation. &lt;/p&gt;  &lt;p&gt;When I was searching for table mapping from dataset to object, the framework was incapable of doing as LINQ to SQL do. So finally I decided to develop my own application which maps object to dataset data and vice versa and finally persists the data into an XML file.&lt;/p&gt;  &lt;p&gt;In this application, I would like to share some information from the application I made using XML as database backend and data table to object mapping on dataset using LINQ. &lt;/p&gt;  &lt;h2 style="color: rgb(255, 153, 0);"&gt;Background&lt;/h2&gt;  &lt;p&gt;As I have said in the introduction part, I was looking for data persistence using XML from dataset. Although I found a lot of snips, I found out data manipulation in the dataset using LINQ easy and powerful which I would like to share.&lt;/p&gt;  &lt;h2 style="color: rgb(255, 153, 0);"&gt;Concepts&lt;/h2&gt;  &lt;p&gt;The general function of the application is to store contacts detail and retrieve contacts from the database, in our case the XML file. The application is designed with separation of layers into three layered architecture, where each layer is separated from the other.&lt;/p&gt;  &lt;p&gt;&lt;img style="width: 506px; height: 260px;" src="http://www.codeproject.com/KB/linq/XmlbasedPhonebook/Archictect.jpg" width="506" height="260" /&gt;&lt;/p&gt;  &lt;ul&gt;&lt;li&gt;The data layer where the data is persisted on XML file&lt;/li&gt;&lt;li&gt;The data access layer and Business layer, in our case the DAL and BL is defined in the DAL class where data is mapped from XML file across the dataset to the contact object as well as data is saved from the active contact class through &lt;code&gt;Dataset &lt;/code&gt;to XML.&lt;/li&gt;&lt;li&gt;The UI where the data presentation is developed using any technology such as Windows Forms, WPF, web, etc. In our case, I develop the UI layer using Windows Forms as an illustration.&lt;/li&gt;&lt;/ul&gt;  &lt;p&gt;Here the main concepts behind the code lies here, once data is loaded from the XML file, it is loaded to dataset, then from the dataset the data is mapped to appropriate contact objects. Like any other ORM tools such as LINQ to SQL, we are doing the mapping manually from dataset to objects. After that, once objects are mapped, the business functionality is manipulated using LINQ on the objects to perform various operations. &lt;/p&gt;  &lt;h2 style="color: rgb(255, 153, 0);"&gt;Using the Code&lt;/h2&gt;  &lt;p&gt;Here the code is divided into two - the first part is designing the data access layer class with business layer which performs all the operations. The second part is the UI which is designed in such a way as to perform various operations of the phonebook application. Here in my application, although I have used only Windows Form for the UI layer, it is easily extended to other UIs like WPF, Web Forms, etc. The DAL layer consists of the &lt;code&gt;contact &lt;/code&gt;class with &lt;code&gt;dataset&lt;/code&gt;: &lt;/p&gt;  &lt;p&gt;&lt;img style="width: 192px; height: 364px;" src="http://www.codeproject.com/KB/linq/XmlbasedPhonebook/DAL.jpg" width="192" height="364" /&gt; &lt;img style="width: 167px; height: 289px;" src="http://www.codeproject.com/KB/linq/XmlbasedPhonebook/contacts.jpg" width="167" height="289" /&gt;&lt;/p&gt;  &lt;h2 style="color: rgb(255, 153, 0);"&gt;Data Reading &lt;/h2&gt;  &lt;p&gt;&lt;code&gt;ReadData()&lt;/code&gt; method reads data from the XML file to the &lt;code&gt;dataset&lt;/code&gt;, and then data row in the &lt;code&gt;dataset &lt;/code&gt;is mapped to &lt;code&gt;contact &lt;/code&gt;object.&lt;/p&gt;  &lt;div style="display: block;" width="100%" id="premain0" class="small-text align-right"&gt;&lt;br /&gt;&lt;span preid="0" style="cursor: pointer; margin-bottom: 0pt;" id="precollapse0"&gt;&lt;/span&gt;&lt;/div&gt;&lt;pre style="margin-top: 0pt;" id="pre0" lang="cs"&gt;&lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt;read  data from the xml file and&lt;br /&gt;&lt;/span&gt;  &lt;span class="code-keyword"&gt;private&lt;/span&gt;  &lt;span class="code-keyword"&gt;void&lt;/span&gt; ReadData()&lt;br /&gt;{&lt;br /&gt;&lt;span class="code-keyword"&gt;try&lt;/span&gt;&lt;br /&gt;{&lt;br /&gt;ds.Clear();&lt;br /&gt;Contacts.Clear();&lt;br /&gt;&lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt;checks  whether the file exists otherwise it create blank file&lt;br /&gt;&lt;/span&gt;  &lt;span class="code-keyword"&gt;if&lt;/span&gt;  (!System.IO.File.Exists(FileName))&lt;br /&gt;{&lt;br /&gt;System.IO.File.Create(FileName);&lt;br /&gt;}&lt;br /&gt;&lt;span class="code-keyword"&gt;else&lt;/span&gt;&lt;br /&gt;{&lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt;read  data to dataset then map the data row to contact object&lt;br /&gt;&lt;/span&gt;  ds.ReadXml(FileName, XmlReadMode.IgnoreSchema);&lt;br /&gt;Contact c;&lt;br /&gt;&lt;span class="code-keyword"&gt;foreach&lt;/span&gt; (DataRow dr &lt;span class="code-keyword"&gt;in&lt;/span&gt; ds.Tables[&lt;span class="code-digit"&gt;0&lt;/span&gt;].Rows)&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;c = &lt;span class="code-keyword"&gt;new&lt;/span&gt; Contact() { SN  = Convert.ToInt32(dr[&lt;span class="code-digit"&gt;0&lt;/span&gt;]),&lt;br /&gt;Name =  dr[&lt;span class="code-digit"&gt;1&lt;/span&gt;].ToString(), Tele = dr[&lt;span class="code-digit"&gt;2&lt;/span&gt;].ToString(),&lt;br /&gt;Email = dr[&lt;span class="code-digit"&gt;3&lt;/span&gt;].ToString(), Gender = Convert.ToChar(dr[&lt;span class="code-digit"&gt;4&lt;/span&gt;]) };&lt;br /&gt;&lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt;added to the contacts  collection&lt;br /&gt;&lt;/span&gt;  Contacts.Add(c);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;span class="code-keyword"&gt;catch&lt;/span&gt;  (Exception ex)&lt;br /&gt;{&lt;br /&gt;Console.WriteLine(ex.Message);&lt;br /&gt;&lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt;throw  (ex);&lt;br /&gt;&lt;/span&gt;  }&lt;br /&gt;} &lt;/pre&gt;  &lt;p&gt;Here the point is that the &lt;code&gt;dataset &lt;/code&gt;is used in mapping the data from XML to the &lt;code&gt;contact &lt;/code&gt;object. Finally the &lt;code&gt;contacts &lt;/code&gt;collection holds the data information of &lt;code&gt;contact &lt;/code&gt;object, at the point querying the object using LINQ becomes easy. &lt;/p&gt;  &lt;h2 style="color: rgb(255, 153, 0);"&gt;Business Operation&lt;/h2&gt;  &lt;p&gt;Now let us look at other typical operations once the data are loaded into the &lt;code&gt;contacts &lt;/code&gt;list, say we want to get all &lt;code&gt;contacts&lt;/code&gt;.&lt;/p&gt;  &lt;div style="display: block;" width="100%" id="premain1" class="small-text align-right"&gt;&lt;br /&gt;&lt;span preid="1" style="cursor: pointer; margin-bottom: 0pt;" id="precollapse1"&gt;&lt;/span&gt;&lt;/div&gt;&lt;pre style="margin-top: 0pt;" id="pre1" lang="cs"&gt;&lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt;using simple LINQ operation we can get all the contacts&lt;br /&gt;&lt;/span&gt;  &lt;span class="code-keyword"&gt;public&lt;/span&gt;  List&lt;contact&gt;  GetContact()&lt;br /&gt;{&lt;br /&gt;&lt;span class="code-keyword"&gt;var&lt;/span&gt;  cont = (from cc &lt;span class="code-keyword"&gt;in&lt;/span&gt;  Contacts&lt;br /&gt;orderby cc.SN&lt;br /&gt;select cc).ToList();&lt;br /&gt;&lt;span class="code-keyword"&gt;return&lt;/span&gt;  cont;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt;for  single contact&lt;br /&gt;&lt;/span&gt;  &lt;span class="code-keyword"&gt;public&lt;/span&gt; Contact GetContact(&lt;span class="code-keyword"&gt;int&lt;/span&gt;  id)&lt;br /&gt;{&lt;br /&gt;&lt;span class="code-keyword"&gt;return&lt;/span&gt;  Contacts.Where(cc =&gt; cc.SN == id).SingleOrDefault();&lt;br /&gt;}&lt;/contact&gt;&lt;/pre&gt;  &lt;p&gt;Again if we look at the typical CRUD operation, the data manipulation is also maintained using a simple operation. However, unlike the typical ADO.NET based database application, all operations are done simply on the list. &lt;/p&gt;  &lt;div style="display: block;" width="100%" id="premain2" class="small-text align-right"&gt;&lt;br /&gt;&lt;span preid="2" style="cursor: pointer; margin-bottom: 0pt;" id="precollapse2"&gt;&lt;/span&gt;&lt;/div&gt;&lt;pre style="margin-top: 0pt;" id="pre2" lang="cs"&gt;  &lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt;to delete contact from the list&lt;br /&gt;&lt;/span&gt;  &lt;span class="code-keyword"&gt;public&lt;/span&gt;  &lt;span class="code-SDKkeyword"&gt;Boolean&lt;/span&gt; DeleteContact(&lt;span class="code-keyword"&gt;int&lt;/span&gt; id)&lt;br /&gt;{    &lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt;remove the contact with the id from the  contacts list&lt;br /&gt;&lt;/span&gt;  &lt;span class="code-keyword"&gt;return&lt;/span&gt;  Contacts.Remove(GetContact(id))?&lt;span class="code-keyword"&gt;true&lt;/span&gt;:&lt;span class="code-keyword"&gt;false&lt;/span&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt;to add contact into list&lt;br /&gt;&lt;/span&gt;  &lt;span class="code-keyword"&gt;public&lt;/span&gt; &lt;span class="code-keyword"&gt;void&lt;/span&gt; AddContact(Contact  c)&lt;br /&gt;{&lt;br /&gt;&lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt;add the  new contact to the Contacts list&lt;br /&gt;&lt;/span&gt;  Contacts.Add(c);&lt;br /&gt;}&lt;br /&gt;&lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt;clear the  list&lt;br /&gt;&lt;/span&gt;  &lt;span class="code-keyword"&gt;public&lt;/span&gt; &lt;span class="code-keyword"&gt;void&lt;/span&gt; clearlist()&lt;br /&gt;{&lt;br /&gt;&lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt;clears the  contacts from the collection&lt;br /&gt;&lt;/span&gt;  Contacts.Clear();&lt;br /&gt;}&lt;/pre&gt;  &lt;h2 style="color: rgb(255, 153, 0);"&gt;Data Saving&lt;/h2&gt;  &lt;p&gt;Finally, only the &lt;code&gt;Contacts &lt;/code&gt;object list is persisted to the XML file when the &lt;code&gt;Save() &lt;/code&gt;method is called. This look like a typical LINQ to SQL operation, where data is saved to the database only when the &lt;code&gt;submitchange()&lt;/code&gt; method of the &lt;code&gt;datacontext &lt;/code&gt;object is called. Here our &lt;code&gt;save &lt;/code&gt;method looks like: &lt;/p&gt;  &lt;pre style="margin-top: 0pt;" id="pre3" lang="cs"&gt;&lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt;maps  the object from the contacts list to datarow in the dataset&lt;br /&gt;&lt;/span&gt;  &lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt;the dataset  is saved to the xml file&lt;br /&gt;&lt;/span&gt;  &lt;span class="code-keyword"&gt;public&lt;/span&gt; &lt;span class="code-SDKkeyword"&gt;Boolean&lt;/span&gt; Save()&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;&lt;span class="code-keyword"&gt;try&lt;/span&gt;&lt;br /&gt;{&lt;br /&gt;ds.Clear();&lt;br /&gt;DataRow  dr;&lt;br /&gt;&lt;span class="code-keyword"&gt;foreach&lt;/span&gt;  (Contact c &lt;span class="code-keyword"&gt;in&lt;/span&gt;  Contacts)&lt;br /&gt;{&lt;br /&gt;dr =  ds.Tables[&lt;span class="code-digit"&gt;0&lt;/span&gt;].NewRow();&lt;br /&gt;dr[&lt;span class="code-digit"&gt;0&lt;/span&gt;] = c.SN;&lt;br /&gt;dr[&lt;span class="code-digit"&gt;1&lt;/span&gt;] = c.Name;&lt;br /&gt;dr[&lt;span class="code-digit"&gt;2&lt;/span&gt;] = c.Tele;&lt;br /&gt;dr[&lt;span class="code-digit"&gt;3&lt;/span&gt;] = c.Email;&lt;br /&gt;dr[&lt;span class="code-digit"&gt;4&lt;/span&gt;] = c.Gender;&lt;br /&gt;ds.Tables[&lt;span class="code-digit"&gt;0&lt;/span&gt;].Rows.Add(dr);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;ds.WriteXml(FileName, XmlWriteMode.IgnoreSchema);&lt;br /&gt;&lt;span class="code-keyword"&gt;return&lt;/span&gt;  &lt;span class="code-keyword"&gt;true&lt;/span&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;span class="code-keyword"&gt;catch&lt;/span&gt;  (Exception ex) {&lt;br /&gt;&lt;br /&gt;&lt;span class="code-keyword"&gt;return&lt;/span&gt;  &lt;span class="code-keyword"&gt;false&lt;/span&gt;;&lt;br /&gt;}  &lt;/pre&gt;  &lt;p&gt;Here the point is reverse to the read operation, where the data is mapped from object to datarow, then finally the data is saved from the dataset to XML file via &lt;code&gt;WriteXml() &lt;/code&gt;method of &lt;code&gt;dataset &lt;/code&gt;object. Finally, the layer is compiled as class library to be referenced from the UI layer.&lt;/p&gt;  &lt;h2 style="color: rgb(255, 153, 0);"&gt;The UI Layer&lt;/h2&gt;  &lt;p&gt;Since the business operation layer is done on the DAL, the operation of UI layer is simply to present the data. The main operation is just referencing the class layer and implements the functionality of the phonebook application in your favorite UI. In my case, I have chosen to implement using the Windows Forms although it is extendable with a little similar manner to web application and WPF.&lt;/p&gt; &lt;img style="width: 640px; height: 276px;" src="http://www.codeproject.com/KB/linq/XmlbasedPhonebook/UIsnapshot.jpg" width="640" height="276" /&gt;  &lt;p&gt;When the Windows Form is loaded, the contacts data is bound to the &lt;code&gt;bindingsource&lt;/code&gt;, where the binding source is used throughout the application for binding the Windows controls on the form and the data grid.&lt;/p&gt;  &lt;div style="display: block;" width="100%" id="premain4" class="small-text align-right"&gt;&lt;br /&gt;&lt;span preid="4" style="cursor: pointer; margin-bottom: 0pt;" id="precollapse4"&gt;&lt;/span&gt;&lt;/div&gt;&lt;pre style="margin-top: 0pt;" id="pre4" lang="cs"&gt;&lt;span class="code-keyword"&gt;using&lt;/span&gt;  Book;&lt;br /&gt;&lt;br /&gt;&lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt;....&lt;br /&gt;&lt;/span&gt;  &lt;span class="code-keyword"&gt;private&lt;/span&gt;  &lt;span class="code-keyword"&gt;void&lt;/span&gt; Form1_Load(&lt;span class="code-keyword"&gt;object&lt;/span&gt;  sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;&lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt;gets all contact in object form&lt;br /&gt;&lt;/span&gt;  bindingSource1.DataSource =  dall.GetContact();&lt;br /&gt;bindsource();&lt;br /&gt;bindControls();&lt;br /&gt;}&lt;br /&gt;&lt;span class="code-keyword"&gt;public&lt;/span&gt;  &lt;span class="code-keyword"&gt;void&lt;/span&gt; bindsource()&lt;br /&gt;{ dgvaddress.DataSource =  bindingSource1;&lt;br /&gt;}&lt;/pre&gt;  &lt;p&gt;Many of the binding source operations are pretty straight forward. I use simply like methods of the binding source like:&lt;/p&gt;  &lt;ul&gt;&lt;li&gt;&lt;code&gt;Bindingsource1.MoveFirst()&lt;/code&gt;&lt;/li&gt;&lt;li&gt;&lt;code&gt;Bindingsource1.MoveNext()&lt;/code&gt;&lt;/li&gt;&lt;li&gt;&lt;code&gt;Bindingsource1.AddNew()&lt;/code&gt;&lt;/li&gt;&lt;/ul&gt;  &lt;p&gt;etc. &lt;/p&gt;  &lt;p&gt;Finally when data editing and manipulation is finished, our DAL class method &lt;code&gt;save &lt;/code&gt;is called to persist the data.&lt;/p&gt;  &lt;div style="display: block;" width="100%" id="premain5" class="small-text align-right"&gt;&lt;img preid="5" style="cursor: pointer;" src="http://www.codeproject.com/images/minus.gif" id="preimg5" width="9" height="9" /&gt;&lt;span preid="5" style="cursor: pointer; margin-bottom: 0pt;" id="precollapse5"&gt; Collapse&lt;/span&gt;&lt;/div&gt;&lt;pre style="margin-top: 0pt;" id="pre5" lang="cs"&gt;&lt;span class="code-keyword"&gt;private&lt;/span&gt;  &lt;span class="code-keyword"&gt;void&lt;/span&gt; btnsave_Click(&lt;span class="code-keyword"&gt;object&lt;/span&gt;  sender, EventArgs e)&lt;br /&gt;{ &lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt;save data  in the grid to xml file&lt;br /&gt;&lt;/span&gt;  AddGridValuetolist();&lt;br /&gt;&lt;span class="code-keyword"&gt;if&lt;/span&gt;  (dall.Save())&lt;br /&gt;MessageBox.Show(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;success"&lt;/span&gt;);&lt;br /&gt;&lt;span class="code-keyword"&gt;else&lt;/span&gt;&lt;br /&gt;MessageBox.Show(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;error"&lt;/span&gt;);&lt;br /&gt;} &lt;/pre&gt;  &lt;p&gt;When the save button is clicked, first the data in the grid is mapped to the contact list, then each contact is added to &lt;code&gt;Contacts &lt;/code&gt;list in the DAL layer class, after that, the &lt;code&gt;save &lt;/code&gt;method of the DAL class is called to save the list data into the XML file.&lt;/p&gt;  &lt;div style="display: block;" width="100%" id="premain6" class="small-text align-right"&gt;&lt;span preid="6" style="cursor: pointer; margin-bottom: 0pt;" id="precollapse6"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;pre style="margin-top: 0pt;" id="pre6" lang="cs"&gt;  &lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt; adds the  datarow from the grid to contact list&lt;br /&gt;&lt;/span&gt;  &lt;span class="code-keyword"&gt;public&lt;/span&gt; &lt;span class="code-keyword"&gt;void&lt;/span&gt; AddGridValuetolist()&lt;br /&gt;{&lt;br /&gt;Contact  c;&lt;br /&gt;dall.clearlist();&lt;br /&gt;&lt;span class="code-keyword"&gt;foreach&lt;/span&gt;  (DataGridViewRow dr &lt;span class="code-keyword"&gt;in&lt;/span&gt;  dgvaddress.Rows)&lt;br /&gt;{&lt;br /&gt;&lt;span class="code-keyword"&gt;if&lt;/span&gt;  (dr.Cells [&lt;span class="code-digit"&gt;2&lt;/span&gt;].Value != &lt;span class="code-keyword"&gt;null&lt;/span&gt;)&lt;br /&gt;{ &lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt;mapping  from datagridviewrow into contact object&lt;br /&gt;&lt;/span&gt;  c = &lt;span class="code-keyword"&gt;new&lt;/span&gt; Contact()&lt;br /&gt;{&lt;br /&gt;SN = Convert.ToInt32(dr.Cells[&lt;span class="code-digit"&gt;0&lt;/span&gt;].Value),&lt;br /&gt;Name = Convert.ToString(dr.Cells[&lt;span class="code-digit"&gt;1&lt;/span&gt;].Value),&lt;br /&gt;Tele = Convert.ToString(dr.Cells[&lt;span class="code-digit"&gt;2&lt;/span&gt;].Value),&lt;br /&gt;Email = Convert.ToString(dr.Cells[&lt;span class="code-digit"&gt;3&lt;/span&gt;].Value),&lt;br /&gt;Gender = Convert.ToChar(dr.Cells[&lt;span class="code-digit"&gt;4&lt;/span&gt;].Value)&lt;br /&gt;};&lt;br /&gt;dall.AddContact(c);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;/pre&gt;  &lt;h2 style="color: rgb(255, 153, 0);"&gt;Conclusion&lt;/h2&gt;  &lt;p&gt;As I have explained in detail, the whole point of the article is focused on creating object to dataset mapping. Here we have created our own way of object persistence to database and data from the XML file to object via the &lt;code&gt;dataset&lt;/code&gt;. In this case, if you are familiar with LINQ to SQL, the &lt;code&gt;datacontext &lt;/code&gt;class creates a mapping of tables in database to objects and vice versa. In our application, the mapping of objects to data in XML is done using &lt;code&gt;dataset &lt;/code&gt;and LINQ queries. When I was developing the application, my main intent was to develop XML based database. However, when I look to some stuff, I couldn’t find any way ORM like tool to work against dataset. Still the LINQ to dataset provides me data listing operation just like any type collection with the data table and data row, whereas the capability for object mapping like in LINQ to SQL is unavailable in LINQ to dataset. This leads me to develop an ORM based application using LINQ to &lt;code&gt;Dataset &lt;/code&gt;finally to XML file.&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.codeproject.com/KB/linq/XmlbasedPhonebook/PhoneBook_src.zip"&gt;source code&lt;/a&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7331742083114938114-6146904742804187164?l=tadeze.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/XwVFYj-sOdauMvRz_cBRB4rQ328/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/XwVFYj-sOdauMvRz_cBRB4rQ328/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/XwVFYj-sOdauMvRz_cBRB4rQ328/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/XwVFYj-sOdauMvRz_cBRB4rQ328/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MyComputingLife/~4/uP48Cu8JjqA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://tadeze.blogspot.com/feeds/6146904742804187164/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=7331742083114938114&amp;postID=6146904742804187164" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7331742083114938114/posts/default/6146904742804187164?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7331742083114938114/posts/default/6146904742804187164?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MyComputingLife/~3/uP48Cu8JjqA/simplified-xml-based-phone-book.html" title="Simplified XML Based Phone Book Database using LINQ" /><author><name>tadesse</name><uri>http://www.blogger.com/profile/01745642569109272755</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>2</thr:total><feedburner:origLink>http://tadeze.blogspot.com/2010/12/simplified-xml-based-phone-book.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0cGRHg-eCp7ImA9Wx5bFko.&quot;"><id>tag:blogger.com,1999:blog-7331742083114938114.post-5440225867621959056</id><published>2010-11-02T08:46:00.000+03:00</published><updated>2010-11-02T09:23:45.650+03:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-11-02T09:23:45.650+03:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="DAL" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="OO Design" /><category scheme="http://www.blogger.com/atom/ns#" term="DRY" /><title>DRY (don’t repeat yourself) Principle in Context of Data Access Layer</title><content type="html">&lt;span style="font-size:100%;"&gt;&lt;b style=""&gt;&lt;span style="line-height: 115%; color: rgb(227, 108, 10);"&gt;Introduction&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;  &lt;p style="text-align: justify;" class="MsoNormal"&gt;&lt;span style="line-height: 115%;font-size:100%;" &gt;Today most objected oriented applications are based on some common architectural design. Today the major architectural pattern is evolved from the pillars of OOP. Besides the pillars of the OOP the basic objected oriented design principle plays a major role in designing the architect of a system. Here in this article I like to share information how DRY principle plays a major role in designing OOP based system.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size:100%;"&gt;&lt;b style=""&gt;&lt;span style="line-height: 115%; color: rgb(227, 108, 10);"&gt;The Principle&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="line-height: 115%;font-size:100%;" &gt;“Avoid duplicating code by abstracting out things that are common and placing those in a single location”.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="text-align: justify;" class="MsoNormal"&gt;&lt;span style="line-height: 115%;font-size:100%;" &gt;Dry is simply about abstracting one requirement in one place. Once you put all duplicate code in one location you are capable for maintaining flexibility of your code. &lt;span style=""&gt; &lt;/span&gt;&lt;span style=""&gt; &lt;/span&gt;If we have a common operation among different types of modules or objects in our system, rather than typing again and again similar code we just generalize the code to make a single module. Then we try to make call (use) that module when ever needed.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoNormal"&gt;&lt;span style="line-height: 115%;font-size:100%;" &gt;&lt;span style=""&gt; &lt;/span&gt;Let us take a simple classic example, assume we want to calculate a permutation of number (&lt;sub&gt;n&lt;/sub&gt;P&lt;sub&gt;r&lt;/sub&gt;) using a procedural like in C. We were told to do the common functionality in one common function, the call that function on need base. In our case since permutation is i.e. &lt;sub&gt;n&lt;/sub&gt;P&lt;sub&gt;r&lt;/sub&gt; = n!/(n-r)! . The first step was, to find the factorial of n then divide to factorial of (n-r)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="line-height: 115%;font-size:100%;" &gt;#include …. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="line-height: 115%;font-size:100%;" &gt;Int factorial(int n)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="line-height: 115%;font-size:100%;" &gt;{// ……factorial of a number&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="line-height: 115%;font-size:100%;" &gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="line-height: 115%;font-size:100%;" &gt;int main() &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="line-height: 115%;font-size:100%;" &gt;{&lt;span style=""&gt;  &lt;/span&gt;int p,n,r;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="line-height: 115%;font-size:100%;" &gt;scanf(“%d%d”,&amp;amp;n,&amp;amp;r);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="line-height: 115%;font-size:100%;" &gt;P = factorial(n)/factorial(n-r);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="line-height: 115%;font-size:100%;" &gt;printf(“Permutation of %d P %d&lt;span style=""&gt;  &lt;/span&gt;= %d”,n,r,p);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="line-height: 115%;font-size:100%;" &gt;return 0;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="line-height: 115%;font-size:100%;" &gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="text-align: justify;" class="MsoNormal"&gt;&lt;span style="line-height: 115%;font-size:100%;" &gt;Here instead of simply calculating factorial of n separately in the main function code and (n-r) in the main function, we separated the repeated code in common function factorial.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoNormal"&gt;&lt;span style="line-height: 115%;font-size:100%;" &gt;DRY principle also asserts like that, it separates the repeated value in common (single) place, then we simply tend to refer to that code. The main advantage behind this is &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p class="MsoListParagraphCxSpFirst" style="text-indent: -0.25in; text-align: justify;"&gt;&lt;!--[if !supportLists]--&gt;&lt;span style="line-height: 115%;font-family:Symbol;font-size:100%;"  &gt;&lt;span style=""&gt;·&lt;span style=""&gt;         &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;span style="line-height: 115%;font-size:100%;" &gt;Code maintainability you don’t have to change every module you just have one module to change&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;!--[if !supportLists]--&gt;&lt;span style="line-height: 115%;font-family:Symbol;font-size:100%;"  &gt;&lt;span style=""&gt;·&lt;span style=""&gt;         &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;span style="line-height: 115%;font-size:100%;" &gt;Requirement is also defined in one location so that whenever there is modification to requirement you can simply spot them&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_YqmizlRd6Ig/TM-qX77jAiI/AAAAAAAAAGQ/yxvB2gk76EU/s1600/image001.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 683px; height: 406px;" src="http://4.bp.blogspot.com/_YqmizlRd6Ig/TM-qX77jAiI/AAAAAAAAAGQ/yxvB2gk76EU/s320/image001.png" alt="" id="BLOGGER_PHOTO_ID_5534829795262792226" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;color:blue;"   &gt;Class&lt;/span&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt; &lt;span style="color: rgb(43, 145, 175);"&gt;Database&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;    &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;readonly&lt;/span&gt; &lt;span style="color:blue;"&gt;static&lt;/span&gt; &lt;span style="color:blue;"&gt;string&lt;/span&gt; connectionString;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;    &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;    &lt;/span&gt;&lt;span style="color:blue;"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;Movie&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;    &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;        &lt;/span&gt;&lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span style="color:blue;"&gt;int&lt;/span&gt; Id { &lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;set&lt;/span&gt;; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;        &lt;/span&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;string&lt;/span&gt; Title { &lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;set&lt;/span&gt;; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;        &lt;/span&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;string&lt;/span&gt; Type { &lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;set&lt;/span&gt;; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;        &lt;/span&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;double&lt;/span&gt; Rate { &lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;set&lt;/span&gt;; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;       &lt;/span&gt;&lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span style="color:blue;"&gt;string&lt;/span&gt; connstr;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;        &lt;/span&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; Movie(&lt;span style="color:blue;"&gt;string&lt;/span&gt; title, &lt;span style="color:blue;"&gt;string&lt;/span&gt; type, &lt;span style="color:blue;"&gt;double&lt;/span&gt; rate)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;        &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;span style="color:blue;"&gt;this&lt;/span&gt;.Title = title;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;span style="color:blue;"&gt;this&lt;/span&gt;.Type = type;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;span style="color:blue;"&gt;this&lt;/span&gt;.Rate = rate;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;        &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;        &lt;/span&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; Save()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;        &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;span style="color:blue;"&gt;string&lt;/span&gt; sql = &lt;span style="color: rgb(163, 21, 21);"&gt;"insert into movie(id,title,type,rate) values("&lt;/span&gt; +&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;               &lt;/span&gt;&lt;span style="color:blue;"&gt;this&lt;/span&gt;.Id + &lt;span style="color: rgb(163, 21, 21);"&gt;",'"&lt;/span&gt; + &lt;span style="color:blue;"&gt;this&lt;/span&gt;.Title + &lt;span style="color: rgb(163, 21, 21);"&gt;"','"&lt;/span&gt; + &lt;span style="color:blue;"&gt;this&lt;/span&gt;.Type + &lt;span style="color: rgb(163, 21, 21);"&gt;"',"&lt;/span&gt; + &lt;span style="color:blue;"&gt;this&lt;/span&gt;.Rate + &lt;span style="color: rgb(163, 21, 21);"&gt;")"&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;span style="color:blue;"&gt;using&lt;/span&gt; (&lt;span style="color: rgb(43, 145, 175);"&gt;SqlConnection&lt;/span&gt; con = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;SqlConnection&lt;/span&gt;(&lt;span style="color: rgb(43, 145, 175);"&gt;Database&lt;/span&gt;.connectionString))&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;            &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;                &lt;/span&gt;con.Open();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;                &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;SqlCommand&lt;/span&gt; cmd = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;SqlCommand&lt;/span&gt;(sql,con);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;               &lt;/span&gt;&lt;span style="color:green;"&gt;// cmd.Connection = con;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;                &lt;/span&gt;cmd.ExecuteNonQuery();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;           &lt;/span&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;            &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;        &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;color:blue;"   &gt;public&lt;/span&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; Update()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;        &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;span style="color:blue;"&gt;string&lt;/span&gt; sql = &lt;span style="color: rgb(163, 21, 21);"&gt;"Update&lt;span style=""&gt;  &lt;/span&gt;movie set(id,title,type,rate) values("&lt;/span&gt; +&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;               &lt;/span&gt;&lt;span style="color:blue;"&gt;this&lt;/span&gt;.Id + &lt;span style="color: rgb(163, 21, 21);"&gt;",'"&lt;/span&gt; + &lt;span style="color:blue;"&gt;this&lt;/span&gt;.Title + &lt;span style="color: rgb(163, 21, 21);"&gt;"','"&lt;/span&gt; + &lt;span style="color:blue;"&gt;this&lt;/span&gt;.Type + &lt;span style="color: rgb(163, 21, 21);"&gt;"',"&lt;/span&gt; + &lt;span style="color:blue;"&gt;this&lt;/span&gt;.Rate + &lt;span style="color: rgb(163, 21, 21);"&gt;")"&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;span style="color:blue;"&gt;using&lt;/span&gt; (&lt;span style="color: rgb(43, 145, 175);"&gt;SqlConnection&lt;/span&gt; con = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;SqlConnection&lt;/span&gt;(&lt;span style="color: rgb(43, 145, 175);"&gt;Database&lt;/span&gt;.connectionString))&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;            &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;                &lt;/span&gt;con.Open();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;                &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;SqlCommand&lt;/span&gt; cmd = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;SqlCommand&lt;/span&gt;(sql,con);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;               &lt;/span&gt;&lt;span style="color:green;"&gt;// cmd.Connection = con;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;                &lt;/span&gt;cmd.ExecuteNonQuery();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;    &lt;/span&gt;&lt;span style=""&gt;             &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;            &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;-----}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;    &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="line-height: 115%;font-size:100%;" &gt;Again Game and movie class also perform these operation in similar manner. The main problem with this design is code is duplicated on all class only with minor changes, this creates problem when any change occurs on the database such as changing from one vendor to other, the whole duplicated code needed to be traced and modified in each class.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size:100%;"&gt;This creates a great problem in code maintenance in large project where we have many classes, during migration of our system from one DB vendor to another. Besides the requirement for the application is also defined in different part of the application event thought they remain the same.&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size:100%;"&gt;&lt;b style=""&gt;&lt;span style="color: rgb(227, 108, 10);"&gt;DRY Solution &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size:100%;"&gt;Today one of the solutions employed for this type of problem is to create a generalization class which is the data access layer (DAL). Using the DAL we try to separate the database from the application classes and perform the operation using common class which is the DAL for the CRUD operation. This design is basically based on the DRY principle as a result every class, in our case Game, Video, Music don’t need to implement their CRUD operation they simply send their operation to the DAL class to perform the CRUD operation.&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size:100%;"&gt;Here the DAL class holds the common database operation done using ADO.NET such as &lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpFirst" style="text-indent: -0.25in;"&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=";font-family:Symbol;font-size:100%;"  &gt;&lt;span style=""&gt;·&lt;span style=""&gt;         &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;span style="font-size:100%;"&gt;ExecuteReader&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle" style="text-indent: -0.25in;"&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=";font-family:Symbol;font-size:100%;"  &gt;&lt;span style=""&gt;·&lt;span style=""&gt;         &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;span style="font-size:100%;"&gt;ExecuteNonQuery&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle" style="text-indent: -0.25in;"&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=";font-family:Symbol;font-size:100%;"  &gt;&lt;span style=""&gt;·&lt;span style=""&gt;         &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;span style="font-size:100%;"&gt;Fill Dataset &lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpLast" style="text-indent: -0.25in;"&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=";font-family:Symbol;font-size:100%;"  &gt;&lt;span style=""&gt;·&lt;span style=""&gt;         &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;span style="font-size:100%;"&gt;ExecuteScalar&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size:100%;"&gt;Since each operation on the database involves the following one or more of the above ADO .NET methods, we tend to encapsulate these methods in the DAL class rather than repeating same code in every class as well as in a multiple methods.&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:100%;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_YqmizlRd6Ig/TM-o9atMBNI/AAAAAAAAAGI/yAf37tmlUVk/s1600/image002.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 637px; height: 357px;" src="http://3.bp.blogspot.com/_YqmizlRd6Ig/TM-o9atMBNI/AAAAAAAAAGI/yAf37tmlUVk/s320/image002.png" alt="" id="BLOGGER_PHOTO_ID_5534828240155968722" border="0" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;p style="margin: 0in 0in 0.0001pt;"&gt;&lt;span style="font-size:100%;"&gt;&lt;v:shape id="Picture_x0020_1" spid="_x0000_i1025" type="#_x0000_t75" style="width: 505.5pt; height: 242.25pt; visibility: visible;"&gt;  &lt;v:imagedata src="file:///C:/Documents%20and%20Settings/cafeuser.TFANUSENTERPRIS/Desktop/DRY%20%28don%E2%80%99t%20repeat%20yourself%29%20Principle%20in%20Context%20of%20Data%20Access%20Layer_files/image002.png" title="clip_image001"&gt; &lt;/v:imagedata&gt;&lt;/v:shape&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size:100%;"&gt;A short snips for a typical operation may look like &lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;color:blue;"   &gt;public&lt;/span&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt; &lt;span style="color:blue;"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;DAL&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;    &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;        &lt;/span&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;static&lt;/span&gt; &lt;span style="color:blue;"&gt;string&lt;/span&gt; connectionstring = &lt;span style="color: rgb(163, 21, 21);"&gt;""&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;        &lt;/span&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;bool&lt;/span&gt; ExecuteNonQuery(&lt;span style="color:blue;"&gt;string&lt;/span&gt; sql)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;        &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;span style="color:blue;"&gt;int&lt;/span&gt; affected;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;span style="color:blue;"&gt;using&lt;/span&gt; (&lt;span style="color: rgb(43, 145, 175);"&gt;SqlConnection&lt;/span&gt; con = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;SqlConnection&lt;/span&gt;(connectionstring))&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;            &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;                &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;SqlCommand&lt;/span&gt; cmd = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;SqlCommand&lt;/span&gt;( sql,con);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;                &lt;/span&gt;con.Open();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;                &lt;/span&gt;affected = cmd.ExecuteNonQuery();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;                &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;            &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;span style="color:blue;"&gt;if&lt;/span&gt; (affected &gt; 0)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;                &lt;/span&gt;&lt;span style="color:blue;"&gt;return&lt;/span&gt; &lt;span style="color:blue;"&gt;true&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;span style="color:blue;"&gt;else&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;                &lt;/span&gt;&lt;span style="color:blue;"&gt;return&lt;/span&gt; &lt;span style="color:blue;"&gt;false&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;        &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;    &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;    &lt;/span&gt;&lt;span style="color:blue;"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;Movie&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;    &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;…..&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;       &lt;/span&gt;Private DAL dal;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;Public Movie(&lt;span style="color:blue;"&gt;string&lt;/span&gt; title, &lt;span style="color:blue;"&gt;string&lt;/span&gt; type, &lt;span style="color:blue;"&gt;double&lt;/span&gt; rate)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;        &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;span style="color:blue;"&gt;this&lt;/span&gt;.Title = title;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;span style="color:blue;"&gt;this&lt;/span&gt;.Type = type;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;span style="color:blue;"&gt;this&lt;/span&gt;.Rate = rate;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size:100%;"&gt;     &lt;/span&gt;&lt;span style="font-size:100%;"&gt;           &lt;/span&gt;&lt;span style="font-size:100%;"&gt;          &lt;/span&gt;&lt;span style="font-size:100%;"&gt;dal=new DAL();&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;        &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;        &lt;/span&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; Save()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:Consolas;font-size:100%;"  &gt;&lt;span style=""&gt;        &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size:100%;"&gt;// here at this point we build simply the sql queries for saving the movie object into &lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size:100%;"&gt;// database&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size:100%;"&gt;String sql = “insert into Movie(title,type,rate) values(‘“+this.Title+”’,’”+this.Type+”’,”+this.Rate”)”;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size:100%;"&gt;dal.executeNonQuery(sql);&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size:100%;"&gt;}&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size:100%;"&gt;//for other operation like delete,update …etc the operation is loosely coupled like this&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size:100%;"&gt;Public void Delete() &lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size:100%;"&gt;{ ///&lt;summary&gt;&lt;/summary&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size:100%;"&gt;/// sql delete operation&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size:100%;"&gt;///&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size:100%;"&gt;}&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size:100%;"&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size:100%;"&gt;Here my point is to explain the DRY principle in context of building DAL class, at this point I simply show a rough small portion of the DAL class. It is assumed that for production environment the class may be build differently with addition of exception handling and other mechanism. &lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size:100%;"&gt;&lt;b style=""&gt;&lt;span style="color: rgb(227, 108, 10);"&gt;Conclusion&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size:100%;"&gt;As the dry principle suggests us to remove the repeated code and put on a common place. In the example I try to show a simple program without repeating common code on our database operation.&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size:100%;"&gt;Although I try to explain the DRY principle in context of the database application, DRY principle is one of the basic objected oriented principles applied in all aspects of OOP. Even when we look at other OOP principles such as SRP they try to avail the DRY principle.&lt;/span&gt;&lt;span style="font-size:100%;"&gt;  &lt;/span&gt;&lt;span style="font-size:100%;"&gt;So the major function of DRY principle is like many OOP principle lower effort to code maintenance by encapsulating the requirement definition on a single place.&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="line-height: 115%;font-size:100%;" &gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7331742083114938114-5440225867621959056?l=tadeze.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/3w2i25Remgl4JCW-b0tEXAKu3VU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/3w2i25Remgl4JCW-b0tEXAKu3VU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/3w2i25Remgl4JCW-b0tEXAKu3VU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/3w2i25Remgl4JCW-b0tEXAKu3VU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MyComputingLife/~4/kIkcL2PevgQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://tadeze.blogspot.com/feeds/5440225867621959056/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=7331742083114938114&amp;postID=5440225867621959056" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7331742083114938114/posts/default/5440225867621959056?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7331742083114938114/posts/default/5440225867621959056?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MyComputingLife/~3/kIkcL2PevgQ/dry-dont-repeat-yourself-principle-in.html" title="DRY (don’t repeat yourself) Principle in Context of Data Access Layer" /><author><name>tadesse</name><uri>http://www.blogger.com/profile/01745642569109272755</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/_YqmizlRd6Ig/TM-qX77jAiI/AAAAAAAAAGQ/yxvB2gk76EU/s72-c/image001.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://tadeze.blogspot.com/2010/11/dry-dont-repeat-yourself-principle-in.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkABR3c7fCp7ImA9WxFQEEs.&quot;"><id>tag:blogger.com,1999:blog-7331742083114938114.post-4862639698677206526</id><published>2010-05-05T16:58:00.000+03:00</published><updated>2010-05-05T17:12:36.904+03:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-05-05T17:12:36.904+03:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="design pattern" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="singleton" /><title>Singleton pattern</title><content type="html">In software engineering, the singleton pattern is a design pattern used to implement the mathematical concept of a singleton, by restricting the instantiation of a class to one object. This is useful when exactly one object is needed to coordinate actions across the system. The concept is sometimes generalized to systems that operate more efficiently when only one object exists, or that restrict the instantiation to a certain number of objects (say, five). Some consider it an anti-pattern, judging that it is overused, introduces unnecessary limitations in situations where a sole instance of a class is not actually required, and introduces global state into an application.&lt;br /&gt;&lt;br /&gt;Implementation&lt;br /&gt;Implementation of a singleton pattern must satisfy the single instance and global access principles. It requires a mechanism to access the singleton class member without creating a class object and a mechanism to persist the value of class members among class objects. The singleton pattern is implemented by creating a class with a method that creates a new instance of the class if one does not exist. If an instance already exists, it simply returns a reference to that object. To make sure that the object cannot be instantiated any other way, the constructor is made protected (not private, because reuse and unit test could need to access the constructor). Note the distinction between a simple static instance of a class and a singleton: although a singleton can be implemented as a static instance, it can also be lazily constructed, requiring no memory or resources until needed. Another notable difference is that static member classes cannot implement an interface, unless that interface is simply a marker. So if the class has to realize a contract expressed by an interface&lt;br /&gt;C#&lt;br /&gt;/// &lt;summary&gt;&lt;br /&gt;/// Thread-safe singleton example created at first call&lt;br /&gt;/// &lt;/summary&gt;&lt;br /&gt;public sealed class Singleton&lt;br /&gt;{&lt;br /&gt;private static readonly Singleton _instance = new Singleton();&lt;br /&gt;&lt;br /&gt;private Singleton() { }&lt;br /&gt;&lt;br /&gt;public static Singleton Instance&lt;br /&gt;{&lt;br /&gt;get&lt;br /&gt;{&lt;br /&gt;return _instance;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;Another method, that utilizes more of the functions of C#, could be used is as follows.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/// &lt;summary&gt;&lt;br /&gt;/// Thread-safe singleton example created at first call&lt;br /&gt;/// &lt;/summary&gt;&lt;br /&gt;public sealed class Singleton&lt;br /&gt;{&lt;br /&gt;/// &lt;summary&gt;&lt;br /&gt;/// Utilizes the get and set auto implemented properties.&lt;br /&gt;/// Note that set; can be any other operator as long as it's&lt;br /&gt;/// less accessible than public.&lt;br /&gt;/// &lt;/summary&gt;&lt;br /&gt;public static Singleton Instance { get; private set; }&lt;br /&gt;&lt;br /&gt;/// &lt;summary&gt;&lt;br /&gt;/// A static constructor is automatically initialized on reference&lt;br /&gt;/// to the class.&lt;br /&gt;/// &lt;/summary&gt;&lt;br /&gt;static Singleton() { Instance = new Singleton(); }&lt;br /&gt;}&lt;br /&gt;Example of use with the factory method pattern&lt;br /&gt;The singleton pattern is often used in conjunction with the factory method pattern to create a system-wide resource whose specific type is not known to the code that uses it. An example of using these two patterns together is the Java Abstract Window Toolkit (AWT).&lt;br /&gt;&lt;br /&gt;java.awt.Toolkit is an abstract class that binds the various AWT components to particular native toolkit implementations. The Toolkit class has a Toolkit.getDefaultToolkit() factory method that returns the platform-specific subclass of Toolkit. The Toolkit object is a singleton because the AWT needs only a single object to perform the binding and the object is relatively expensive to create. The toolkit methods must be implemented in an object and not as static methods of a class because the specific implementation is not known by the platform-independent components. The name of the specific Toolkit subclass used is specified by the "awt.toolkit" environment property accessed through System.getProperties().&lt;br /&gt;&lt;br /&gt;The binding performed by the toolkit allows, for example, the backing implementation of a java.awt.Window to bind to the platform-specific java.awt.peer.WindowPeer implementation. Neither the Window class nor the application using the window needs to be aware of which platform-specific subclass of the peer is used.&lt;br /&gt;&lt;br /&gt; &lt;strong&gt;Drawbacks&lt;/strong&gt;&lt;br /&gt;It should be noted that this pattern makes unit testing far more difficult[6], as it introduces global state into an application.&lt;br /&gt;&lt;br /&gt;It should also be noted that this pattern reduces the potential for parallelism within a program, because access to the singleton in a multi-threaded context must be serialised, i.e. by locking.&lt;br /&gt;&lt;br /&gt;Advocates of dependency injection would regard this as an anti-pattern, mainly due to its use of private and static methods.&lt;br /&gt;&lt;br /&gt;Some have suggested ways to break down the singleton pattern using methods such as reflection in languages such as Java&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7331742083114938114-4862639698677206526?l=tadeze.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/SncvwRvm5O6kFX0FfIMJHRsMQQQ/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/SncvwRvm5O6kFX0FfIMJHRsMQQQ/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/SncvwRvm5O6kFX0FfIMJHRsMQQQ/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/SncvwRvm5O6kFX0FfIMJHRsMQQQ/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MyComputingLife/~4/9BLRS2eDq4A" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://tadeze.blogspot.com/feeds/4862639698677206526/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=7331742083114938114&amp;postID=4862639698677206526" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7331742083114938114/posts/default/4862639698677206526?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7331742083114938114/posts/default/4862639698677206526?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MyComputingLife/~3/9BLRS2eDq4A/singleton-pattern.html" title="Singleton pattern" /><author><name>tadesse</name><uri>http://www.blogger.com/profile/01745642569109272755</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://tadeze.blogspot.com/2010/05/singleton-pattern.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkUMR3c8cSp7ImA9WxBXFE4.&quot;"><id>tag:blogger.com,1999:blog-7331742083114938114.post-4106886921907117474</id><published>2010-01-25T19:39:00.000+03:00</published><updated>2010-01-25T19:51:26.979+03:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-01-25T19:51:26.979+03:00</app:edited><title>Type system</title><content type="html">Types can be &lt;a href="http://en.wikipedia.org/wiki/Primitive_data_type" title="Primitive data type"&gt;primitive&lt;/a&gt;, and just hold single pieces of information such as an &lt;a href="http://en.wikipedia.org/wiki/Integer" title="Integer"&gt;integer&lt;/a&gt;, a &lt;a href="http://en.wikipedia.org/wiki/Floating_point" title="Floating point"&gt;floating point&lt;/a&gt;, or a &lt;a href="http://en.wikipedia.org/wiki/Character_%28computing%29" title="Character (computing)"&gt;character&lt;/a&gt; or they can be more complicated &lt;a href="http://en.wikipedia.org/wiki/Composite_type" title="Composite type" class="mw-redirect"&gt;composite&lt;/a&gt; &lt;a href="http://en.wikipedia.org/wiki/Object_%28computer_science%29" title="Object (computer science)"&gt;objects&lt;/a&gt; which store multiple pieces of information--some combination of data and, at times, even functionality. In &lt;a href="http://en.wikipedia.org/wiki/Computer_science" title="Computer science"&gt;computer science&lt;/a&gt;, a &lt;i&gt;type system&lt;/i&gt; may be loosely defined as providing a way to associate one (or more) type(s) with each value that can be used in a program. Just like spoken languages, computer languages have grammars that give the rules to construct phrases and sentences.&lt;br /&gt;&lt;h2&gt;&lt;span class="mw-headline" id="Type_checking"&gt;Type checking&lt;/span&gt;&lt;/h2&gt; &lt;p&gt;The process of verifying and enforcing the constraints of types – &lt;i&gt;type checking&lt;/i&gt; – may occur either at &lt;a href="http://en.wikipedia.org/wiki/Compile-time" title="Compile-time" class="mw-redirect"&gt;compile-time&lt;/a&gt; (a static check) or &lt;a href="http://en.wikipedia.org/wiki/Run-time" title="Run-time" class="mw-redirect"&gt;run-time&lt;/a&gt; (a dynamic check). If a language specification requires its typing rules strongly (ie, more or less allowing only those automatic type conversions which do not lose information), one can refer to the process as &lt;i&gt;strongly typed&lt;/i&gt;, if not, as &lt;i&gt;weakly typed&lt;/i&gt;. The terms are not used in a strict sense.&lt;/p&gt; &lt;h3&gt;&lt;span class="editsection"&gt;&lt;/span&gt; &lt;span class="mw-headline" id="Static_typing"&gt;Static typing&lt;/span&gt;&lt;/h3&gt; &lt;p&gt;A programming language is said to use static typing when type checking is performed during compile-time as opposed to run-time. In static typing, types are associated with variables not values. Statically typed languages include &lt;a href="http://en.wikipedia.org/wiki/Ada_%28programming_language%29" title="Ada (programming language)"&gt;Ada&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/ActionScript" title="ActionScript"&gt;AS3&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/C_%28programming_language%29" title="C (programming language)"&gt;C&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/C%2B%2B" title="C++"&gt;C++&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/C_Sharp_%28programming_language%29" title="C Sharp (programming language)"&gt;C#&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/F_Sharp_%28programming_language%29" title="F Sharp (programming language)"&gt;F#&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/JADE_%28programming_language%29" title="JADE (programming language)"&gt;JADE&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Java_%28programming_language%29" title="Java (programming language)"&gt;Java&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Fortran" title="Fortran"&gt;Fortran&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Haskell_%28programming_language%29" title="Haskell (programming language)"&gt;Haskell&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/ML_%28programming_language%29" title="ML (programming language)"&gt;ML&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Pascal_%28programming_language%29" title="Pascal (programming language)"&gt;Pascal&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Perl" title="Perl"&gt;Perl&lt;/a&gt; (with respect to distinguishing scalars, arrays, hashes and subroutines) and &lt;a href="http://en.wikipedia.org/wiki/Scala_%28programming_language%29" title="Scala (programming language)"&gt;Scala&lt;/a&gt;. Static typing is a limited form of &lt;a href="http://en.wikipedia.org/wiki/Program_verification" title="Program verification" class="mw-redirect"&gt;program verification&lt;/a&gt; (see &lt;a href="http://en.wikipedia.org/wiki/Type_safety" title="Type safety"&gt;type safety&lt;/a&gt;): accordingly, it allows many type errors to be &lt;a href="http://en.wikipedia.org/wiki/Fail-fast" title="Fail-fast"&gt;caught early&lt;/a&gt; in the development cycle. Static type checkers evaluate only the type information that can be determined at compile time, but are able to verify that the checked conditions hold for all possible executions of the program, which eliminates the need to repeat type checks every time the program is executed. Program execution may also be made more efficient (i.e. faster or taking reduced memory) by omitting runtime type checks and enabling other optimizations.&lt;/p&gt; &lt;p&gt;Because they evaluate type information during compilation, and therefore lack type information that is only available at run-time, static type checkers are conservative. They will reject some programs that may be well-behaved at run-time, but that cannot be statically determined to be well-typed. For example, even if an expression &lt;code&gt;&lt;complex&gt;&lt;/complex&gt;&lt;/code&gt; always evaluates to &lt;code&gt;true&lt;/code&gt; at run-time, a program containing the code&lt;/p&gt; &lt;dl&gt;&lt;dd&gt;&lt;code&gt;if &lt;complex&gt; then 42 else &lt;type&gt;&lt;/type&gt;&lt;/complex&gt;&lt;/code&gt;&lt;/dd&gt;&lt;/dl&gt; &lt;p&gt;will be rejected as ill-typed, because a static analysis cannot determine that the &lt;code&gt;else&lt;/code&gt; branch won't be taken.&lt;sup id="cite_ref-pierce2002_0-1" class="reference"&gt;&lt;a href="http://en.wikipedia.org/wiki/Dynamic_type#cite_note-pierce2002-0"&gt;&lt;span&gt;[&lt;/span&gt;1&lt;span&gt;]&lt;/span&gt;&lt;/a&gt;&lt;/sup&gt; The conservative behaviour of static type checkers is advantageous when &lt;code&gt;&lt;complex&gt;&lt;/complex&gt;&lt;/code&gt; evaluates to &lt;code&gt;false&lt;/code&gt; infrequently: A static type checker can detect type errors in rarely used code paths. Without static type checking, even &lt;a href="http://en.wikipedia.org/wiki/Code_coverage" title="Code coverage"&gt;code coverage tests&lt;/a&gt; with 100% code coverage may be unable to find such type errors. Code coverage tests may fail to detect such type errors because the combination of all places where values are created and all places where a certain value is used must be taken into account.&lt;/p&gt; &lt;p&gt;The most widely &lt;a href="http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html" class="external text" rel="nofollow"&gt;used&lt;/a&gt; statically typed languages are not formally &lt;a href="http://en.wikipedia.org/wiki/Type_safety" title="Type safety"&gt;type safe&lt;/a&gt;. They have "&lt;a href="http://en.wikipedia.org/wiki/Loopholes" title="Loopholes" class="mw-redirect"&gt;loopholes&lt;/a&gt;" in the &lt;a href="http://en.wikipedia.org/wiki/Programming_language_specification" title="Programming language specification"&gt;programming language specification&lt;/a&gt; enabling programmers to write code that circumvents the verification performed by a static type checker and so address a wider range of problems. For example, most C-style languages have &lt;a href="http://en.wikipedia.org/wiki/Type_punning" title="Type punning"&gt;type punning&lt;/a&gt;, and Haskell has such features as &lt;code&gt;unsafePerformIO&lt;/code&gt;: such operations may be unsafe at runtime, in that they can cause unwanted behaviour due to incorrect typing of values when the program runs.&lt;/p&gt; &lt;h3&gt;&lt;span class="editsection"&gt;&lt;/span&gt;&lt;span class="mw-headline" id="Dynamic_typing"&gt;Dynamic typing&lt;/span&gt;&lt;/h3&gt; &lt;p&gt;A programming language is said to be dynamically typed, when the majority of its type checking is performed at run-time as opposed to at compile-time. In dynamic typing, types are associated with values not variables. Dynamically typed languages include &lt;a href="http://en.wikipedia.org/wiki/Erlang_%28programming_language%29" title="Erlang (programming language)"&gt;Erlang&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Groovy_%28programming_language%29" title="Groovy (programming language)"&gt;Groovy&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/JavaScript" title="JavaScript"&gt;JavaScript&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Lisp_%28programming_language%29" title="Lisp (programming language)"&gt;Lisp&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Lua_%28programming_language%29" title="Lua (programming language)"&gt;Lua&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Objective-C" title="Objective-C"&gt;Objective-C&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Perl" title="Perl"&gt;Perl&lt;/a&gt; (with respect to user-defined types but not built-in types), &lt;a href="http://en.wikipedia.org/wiki/PHP" title="PHP"&gt;PHP&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Prolog_%28programming_language%29" title="Prolog (programming language)" class="mw-redirect"&gt;Prolog&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Python_%28programming_language%29" title="Python (programming language)"&gt;Python&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Ruby_%28programming_language%29" title="Ruby (programming language)"&gt;Ruby&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Smalltalk" title="Smalltalk"&gt;Smalltalk&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/Tcl" title="Tcl"&gt;Tcl&lt;/a&gt;. Compared to static typing, dynamic typing can be more flexible (e.g. by allowing programs to generate types and functionality based on run-time data), though at the expense of fewer a priori guarantees. This is because a dynamically typed language accepts and attempts to execute some programs which may be ruled as invalid by a static type checker. The term '&lt;a href="http://en.wikipedia.org/wiki/Dynamic_programming_language" title="Dynamic programming language"&gt;dynamic language&lt;/a&gt;' means something different ('runtime dynamism') and a dynamic language is not necessarily dynamically typed.&lt;/p&gt; &lt;p&gt;Dynamic typing may result in runtime type errors—that is, at runtime, a value may have an unexpected type, and an operation nonsensical for that type is applied. This operation may occur long after the place where the programming mistake was made—that is, the place where the wrong type of data passed into a place it should not have. This may make the bug difficult to locate.&lt;/p&gt; &lt;p&gt;Dynamically typed language systems, compared to their statically typed cousins, make fewer "compile-time" checks on the source code (but will check, for example, that the program is syntactically correct). Run-time checks can potentially be more sophisticated, since they can use dynamic information as well as any information that was present during compilation. On the other hand, runtime checks only assert that conditions hold in a particular execution of the program, and these checks are repeated for every execution of the program.&lt;/p&gt; &lt;p&gt;Development in dynamically typed languages is often supported by programming practices such as &lt;a href="http://en.wikipedia.org/wiki/Unit_testing" title="Unit testing"&gt;unit testing&lt;/a&gt;. Testing is a key practice in professional software development, and is particularly important in dynamically typed languages. In practice, the testing done to ensure correct program operation can detect a much wider range of errors than static type-checking, but conversely cannot search as comprehensively for the errors that both testing and static type checking are able to detect. Testing can be incorporated into the &lt;a href="http://en.wikipedia.org/wiki/Software_build" title="Software build"&gt;software build&lt;/a&gt; cycle, in which case it can be thought of as a "compile-time" check, in that the program user will not have to manually run such tests.&lt;/p&gt; &lt;h3&gt;&lt;span class="editsection"&gt;&lt;/span&gt; &lt;span class="mw-headline" id="Combinations_of_dynamic_and_static_typing"&gt;Combinations of dynamic and static typing&lt;/span&gt;&lt;/h3&gt; &lt;p&gt;The presence of static typing in a programming language does not necessarily imply the absence of all dynamic typing mechanisms. For example, Java, and various other object-oriented languages, while using static typing, require for certain operations (&lt;a href="http://en.wikipedia.org/wiki/Downcasting" title="Downcasting"&gt;downcasting&lt;/a&gt;) the support of runtime type tests, a form of dynamic typing. See &lt;a href="http://en.wikipedia.org/wiki/Programming_language" title="Programming language"&gt;programming language&lt;/a&gt; for more discussion of the interactions between static and dynamic typing.&lt;/p&gt; &lt;h3&gt;&lt;span class="editsection"&gt;&lt;/span&gt; &lt;span class="mw-headline" id="Static_and_dynamic_type_checking_in_practice"&gt;Static and dynamic type checking in practice&lt;/span&gt;&lt;/h3&gt; &lt;p&gt;The choice between static and dynamic typing requires &lt;a href="http://en.wikipedia.org/wiki/Trade-off" title="Trade-off"&gt;trade-offs&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;Static typing can find type errors reliably at compile time. This should increase the reliability of the delivered program. However, programmers disagree over how commonly type errors occur, and thus what proportion of those bugs which are written would be caught by static typing. Static typing advocates believe programs are more reliable when they have been well type-checked, while dynamic typing advocates point to distributed code that has proven reliable and to small bug databases. The value of static typing, then, presumably increases as the strength of the type system is increased. Advocates of &lt;a href="http://en.wikipedia.org/wiki/Dependent_type" title="Dependent type"&gt;dependently typed languages&lt;/a&gt; such as &lt;a href="http://en.wikipedia.org/wiki/Dependent_ML" title="Dependent ML"&gt;Dependent ML&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/Epigram_%28programming_language%29" title="Epigram (programming language)"&gt;Epigram&lt;/a&gt; have suggested that almost all bugs can be considered type errors, if the types used in a program are properly declared by the programmer or correctly inferred by the compiler.&lt;sup id="cite_ref-2" class="reference"&gt;&lt;a href="http://en.wikipedia.org/wiki/Dynamic_type#cite_note-2"&gt;&lt;span&gt;[&lt;/span&gt;3&lt;span&gt;]&lt;/span&gt;&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt; &lt;p&gt;Static typing usually results in compiled code that executes more quickly. When the compiler knows the exact data types that are in use, it can produce optimized machine code. Further, compilers for statically typed languages can find assembler shortcuts more easily. Some dynamically typed languages such as &lt;a href="http://en.wikipedia.org/wiki/Common_Lisp" title="Common Lisp"&gt;Common Lisp&lt;/a&gt; allow optional type declarations for optimization for this very reason. Static typing makes this pervasive. See &lt;a href="http://en.wikipedia.org/wiki/Optimization_%28computer_science%29" title="Optimization (computer science)" class="mw-redirect"&gt;optimization&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;By contrast, dynamic typing may allow compilers to run more quickly and allow interpreters to dynamically load new code, since changes to source code in dynamically typed languages may result in less checking to perform and less code to revisit. This too may reduce the edit-compile-test-debug cycle.&lt;/p&gt; &lt;p&gt;Statically typed languages which lack &lt;a href="http://en.wikipedia.org/wiki/Type_inference" title="Type inference"&gt;type inference&lt;/a&gt; (such as Java and C) require that programmers declare the types they intend a method or function to use. This can serve as additional documentation for the program, which the compiler will not permit the programmer to ignore or permit to drift out of synchronization. However, a language can be statically typed without requiring type declarations (examples include &lt;a href="http://en.wikipedia.org/wiki/Haskell_%28programming_language%29" title="Haskell (programming language)"&gt;Haskell&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Scala_%28programming_language%29" title="Scala (programming language)"&gt;Scala&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/C_Sharp_%28programming_language%29#Local_variable_type_inference" title="C Sharp (programming language)"&gt;C#3.0&lt;/a&gt;), so this is not a necessary consequence of static typing.&lt;/p&gt; &lt;p&gt;Dynamic typing allows constructs that some static type checking would reject as illegal. For example, &lt;i&gt;&lt;a href="http://en.wikipedia.org/wiki/Eval" title="Eval"&gt;eval&lt;/a&gt;&lt;/i&gt; functions, which execute arbitrary data as code, become possible (however, the typing within that evaluated code might remain static). Furthermore, dynamic typing better accommodates transitional code and prototyping, such as allowing a placeholder data structure (&lt;a href="http://en.wikipedia.org/wiki/Mock_object" title="Mock object"&gt;mock object&lt;/a&gt;) to be transparently used in place of a full-fledged data structure (usually for the purposes of experimentation and testing). Recent enhancements to statically typed languages (e.g. Haskell &lt;a href="http://en.wikipedia.org/wiki/GADT" title="GADT" class="mw-redirect"&gt;Generalized algebraic data types&lt;/a&gt;) have allowed eval functions to be written in a statically type checked way.&lt;sup id="cite_ref-3" class="reference"&gt;&lt;a href="http://en.wikipedia.org/wiki/Dynamic_type#cite_note-3"&gt;&lt;span&gt;[&lt;/span&gt;4&lt;span&gt;]&lt;/span&gt;&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt; &lt;p&gt;Dynamic typing typically makes &lt;a href="http://en.wikipedia.org/wiki/Metaprogramming" title="Metaprogramming"&gt;metaprogramming&lt;/a&gt; more effective and easier to use. For example, &lt;a href="http://en.wikipedia.org/wiki/C%2B%2B" title="C++"&gt;C++&lt;/a&gt; &lt;a href="http://en.wikipedia.org/wiki/Template_%28programming%29" title="Template (programming)"&gt;templates&lt;/a&gt; are typically more cumbersome to write than the equivalent &lt;a href="http://en.wikipedia.org/wiki/Ruby_programming_language" title="Ruby programming language" class="mw-redirect"&gt;Ruby&lt;/a&gt; or &lt;a href="http://en.wikipedia.org/wiki/Python_%28programming_language%29" title="Python (programming language)"&gt;Python&lt;/a&gt; code.&lt;sup class="noprint Template-Fact" title="This claim needs references to reliable sources from December 2007" style="white-space: nowrap;"&gt;[&lt;i&gt;&lt;a href="http://en.wikipedia.org/wiki/Wikipedia:Citation_needed" title="Wikipedia:Citation needed"&gt;citation needed&lt;/a&gt;&lt;/i&gt;]&lt;/sup&gt; More advanced run-time constructs such as &lt;a href="http://en.wikipedia.org/wiki/Metaclass" title="Metaclass"&gt;metaclasses&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/Introspection_%28computer_science%29" title="Introspection (computer science)" class="mw-redirect"&gt;introspection&lt;/a&gt; are often more difficult to use in statically typed languages.&lt;/p&gt;&lt;br /&gt;&lt;h3&gt;&lt;span class="mw-headline" id="Strong_and_weak_typing"&gt;Strong and weak typing&lt;/span&gt;&lt;/h3&gt; &lt;div class="rellink relarticle mainarticle"&gt;Main article: &lt;a href="http://en.wikipedia.org/wiki/Strongly_typed_programming_language" title="Strongly typed programming language"&gt;Strongly typed programming language&lt;/a&gt;&lt;/div&gt; &lt;p&gt;One definition of &lt;i&gt;strongly typed&lt;/i&gt; involves preventing success for an operation on arguments which have the wrong type. A &lt;a href="http://en.wikipedia.org/wiki/C_%28programming_language%29" title="C (programming language)"&gt;C&lt;/a&gt; &lt;a href="http://en.wikipedia.org/wiki/Type_conversion" title="Type conversion"&gt;cast&lt;/a&gt; gone wrong exemplifies the problem of absent strong typing; if a programmer casts a value from one type to another in C, not only must the compiler allow the code at compile time, but the runtime must allow it as well. This may permit more compact and faster C code, but it can make &lt;a href="http://en.wikipedia.org/wiki/Debugging" title="Debugging"&gt;debugging&lt;/a&gt; more difficult.&lt;/p&gt; &lt;p&gt;Some observers use the term &lt;i&gt;memory-safe language&lt;/i&gt; (or just &lt;i&gt;safe language&lt;/i&gt;) to describe languages that do not allow undefined operations to occur. For example, a memory-safe language will &lt;a href="http://en.wikipedia.org/wiki/Bounds_checking" title="Bounds checking"&gt;check array bounds&lt;/a&gt;, or else statically guarantee (i.e., at compile time before execution) that array accesses out of the array boundaries will cause compile-time and perhaps runtime errors.&lt;/p&gt; &lt;p&gt;&lt;i&gt;Weak typing&lt;/i&gt; means that a language implicitly converts (or casts) types when used. Revisiting the previous example, we have:&lt;/p&gt; &lt;pre&gt;&lt;b&gt;var&lt;/b&gt; x := 5;    &lt;i&gt;// (1)&lt;/i&gt;  (x is an integer)&lt;br /&gt;&lt;b&gt;var&lt;/b&gt; y := "37"; &lt;i&gt;// (2)&lt;/i&gt;  (y is a string)&lt;br /&gt;x + y;         &lt;i&gt;// (3)&lt;/i&gt;  (?)&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt; &lt;p&gt;In a weakly typed language, the result of this operation is not clear. Some languages, such as &lt;a href="http://en.wikipedia.org/wiki/Visual_Basic" title="Visual Basic"&gt;Visual Basic&lt;/a&gt;, would produce runnable code producing the result 42: the system would convert the string "37" into the number 37 to forcibly make sense of the operation. Other languages like &lt;a href="http://en.wikipedia.org/wiki/JavaScript" title="JavaScript"&gt;JavaScript&lt;/a&gt; would produce the result "537": the system would convert the number 5 to the string "5" and then concatenate the two. In both Visual Basic and JavaScript, the resulting type is determined by rules that take both &lt;a href="http://en.wikipedia.org/wiki/Operands" title="Operands" class="mw-redirect"&gt;operands&lt;/a&gt; into consideration. In some languages, such as &lt;a href="http://en.wikipedia.org/wiki/AppleScript" title="AppleScript"&gt;AppleScript&lt;/a&gt;, the type of the resulting value is determined by the type of the left-most operand only.&lt;/p&gt; &lt;h3&gt;&lt;span class="editsection"&gt;&lt;/span&gt;&lt;span class="mw-headline" id="Safely_and_unsafely_typed_systems"&gt;Safely and unsafely typed systems&lt;/span&gt;&lt;/h3&gt; &lt;div class="rellink relarticle mainarticle"&gt;Main article: &lt;a href="http://en.wikipedia.org/wiki/Type_safety" title="Type safety"&gt;Type safety&lt;/a&gt;&lt;/div&gt; &lt;p&gt;A third way of categorizing the type system of a programming language uses the safety of typed operations and conversions. Computer scientists consider a language "type-safe" if it does not allow operations or conversions which lead to erroneous conditions.&lt;/p&gt; &lt;pre&gt;&lt;b&gt;var&lt;/b&gt; x := 5;     &lt;i&gt;// (1)&lt;/i&gt;&lt;br /&gt;&lt;b&gt;var&lt;/b&gt; y := "37";  &lt;i&gt;// (2)&lt;/i&gt;&lt;br /&gt;&lt;b&gt;var&lt;/b&gt; z := x + y; &lt;i&gt;// (3)&lt;/i&gt;&lt;br /&gt;&lt;/pre&gt; &lt;p&gt;In languages like &lt;a href="http://en.wikipedia.org/wiki/Visual_Basic_programming_language" title="Visual Basic programming language" class="mw-redirect"&gt;Visual Basic&lt;/a&gt; variable z in the example acquires the value 42. While the programmer may or may not have intended this, the language defines the result specifically, and the program does not crash or assign an ill-defined value to z. In this respect, such languages are type-safe; however, if the value of y was a string that could not be converted to a number (eg "hello world"), the results would be undefined. Such languages are type-safe (in that they will not crash) but can easily produce undesirable results.&lt;/p&gt; &lt;p&gt;Now let us look at the same example in C:&lt;/p&gt; &lt;pre&gt;&lt;b&gt;int&lt;/b&gt; x = 5;&lt;br /&gt;&lt;b&gt;char&lt;/b&gt; y[] = "37";&lt;br /&gt;&lt;b&gt;char*&lt;/b&gt; z = x + y;&lt;br /&gt;&lt;/pre&gt; &lt;p&gt;In this example z will point to a memory address five characters beyond y, equivalent to three characters after the terminating zero character of the string pointed to by y. The content of that location is undefined, and might lie outside addressable memory. The mere computation of such a pointer may result in undefined behavior (including the program crashing) according to C standards, and in typical systems &lt;a href="http://en.wikipedia.org/wiki/Dereference" title="Dereference" class="mw-redirect"&gt;dereferencing&lt;/a&gt; z at this point could cause the program to crash. We have a well-typed, but not memory-safe program — a condition that cannot occur in a type-safe language.&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:trebuchet ms;"&gt;For more on type system refer to &lt;/span&gt;&lt;a style="font-family: trebuchet ms;" href="http://en.wikipedia.org/wiki/Dynamic_type"&gt;Type System&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7331742083114938114-4106886921907117474?l=tadeze.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/KS9hkopHAeC3rlWkoaXp51wlJmc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/KS9hkopHAeC3rlWkoaXp51wlJmc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/KS9hkopHAeC3rlWkoaXp51wlJmc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/KS9hkopHAeC3rlWkoaXp51wlJmc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MyComputingLife/~4/e6YmGGMU92I" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://tadeze.blogspot.com/feeds/4106886921907117474/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=7331742083114938114&amp;postID=4106886921907117474" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7331742083114938114/posts/default/4106886921907117474?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7331742083114938114/posts/default/4106886921907117474?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MyComputingLife/~3/e6YmGGMU92I/type-system.html" title="Type system" /><author><name>tadesse</name><uri>http://www.blogger.com/profile/01745642569109272755</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://tadeze.blogspot.com/2010/01/type-system.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CE4MQnwzfip7ImA9WxBXE0g.&quot;"><id>tag:blogger.com,1999:blog-7331742083114938114.post-5097871632523132075</id><published>2010-01-24T20:01:00.000+03:00</published><updated>2010-01-24T20:09:43.286+03:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-01-24T20:09:43.286+03:00</app:edited><title>Reflection-oriented programming</title><content type="html">&lt;p&gt;Reflection-oriented programming, or reflective programming, is a functional extension to the object-oriented programming paradigm. Reflection-oriented programming includes self-examination, self-modification, and self-replication. However, the emphasis of the reflection-oriented paradigm is dynamic program modification, which can be determined and executed at runtime. Some &lt;a href="http://en.wikipedia.org/wiki/Imperative_programming" title="Imperative programming"&gt;imperative&lt;/a&gt; approaches, such as procedural and object-oriented programming paradigms, specify that there is an exact predetermined sequence of operations with which to process data. The reflection-oriented programming paradigm, however, adds that program instructions can be modified dynamically at runtime and invoked in their modified state. That is, the program architecture itself can be decided at runtime based upon the data, services, and specific operations that are applicable at runtime.&lt;/p&gt; &lt;p&gt;Programming sequences can be classified in one of two ways, atomic or compound. Atomic operations are those that can be viewed as completing in a single, logical step, such as the addition of two numbers. Compound operations are those that require a series of multiple atomic operations.&lt;/p&gt; &lt;p&gt;A compound statement, in classic procedural or object-oriented programming, can lose its structure once it is compiled. The reflective programming paradigm introduces the concept of &lt;a href="http://en.wikipedia.org/wiki/Metadata" title="Metadata"&gt;&lt;i&gt;meta-information&lt;/i&gt;&lt;/a&gt;, which keeps knowledge of program structure. Meta-information stores information such as the name of the contained methods, the name of the class, the name of parent classes, and/or what the compound statement is supposed to do. Using this stored information, as an object is consumed (processed), it can be reflected upon to find out the operations that it supports. The operation that issues in the required state via the desired state transition can be chosen at run-time without hard-coding it.&lt;/p&gt;&lt;p&gt;Examples&lt;/p&gt;&lt;h3&gt;&lt;span class="mw-headline" id="C.23"&gt;C#&lt;/span&gt;&lt;/h3&gt; &lt;p&gt;Here is an example in &lt;a href="http://en.wikipedia.org/wiki/C_Sharp_%28programming_language%29" title="C Sharp (programming language)"&gt;C#&lt;/a&gt;:&lt;/p&gt; &lt;div dir="ltr" class="mw-geshi" style="text-align: left;"&gt; &lt;div class="csharp source-csharp" style="font-family: monospace;"&gt; &lt;pre class="de1"&gt;&lt;span class="co1"&gt;//Without reflection&lt;/span&gt;&lt;br /&gt;Foo foo &lt;span class="sy0"&gt;=&lt;/span&gt; &lt;span class="kw3"&gt;new&lt;/span&gt; Foo&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy0"&gt;;&lt;/span&gt;&lt;br /&gt;foo.&lt;span class="me1"&gt;Hello&lt;/span&gt;&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy0"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="co1"&gt;//With reflection&lt;/span&gt;&lt;br /&gt;Type t &lt;span class="sy0"&gt;=&lt;/span&gt; Type.&lt;span class="me1"&gt;GetType&lt;/span&gt;&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="st0"&gt;"FooNamespace.Foo"&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy0"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="kw4"&gt;object&lt;/span&gt; foo &lt;span class="sy0"&gt;=&lt;/span&gt; Activator.&lt;span class="me1"&gt;CreateInstance&lt;/span&gt;&lt;span class="br0"&gt;(&lt;/span&gt;t&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy0"&gt;;&lt;/span&gt;&lt;br /&gt;t.&lt;span class="me1"&gt;InvokeMember&lt;/span&gt;&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="st0"&gt;"Hello"&lt;/span&gt;, BindingFlags.&lt;span class="me1"&gt;InvokeMethod&lt;/span&gt;, &lt;span class="kw1"&gt;null&lt;/span&gt;, foo, &lt;span class="kw1"&gt;null&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy0"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt; &lt;/div&gt; &lt;h3&gt;&lt;span class="editsection"&gt;&lt;/span&gt; &lt;span class="mw-headline" id="Common_Lisp"&gt;Common Lisp&lt;/span&gt;&lt;/h3&gt; &lt;p&gt;Here is an equivalent example in &lt;a href="http://en.wikipedia.org/wiki/Common_Lisp" title="Common Lisp"&gt;Common Lisp&lt;/a&gt;:&lt;/p&gt; &lt;div dir="ltr" class="mw-geshi" style="text-align: left;"&gt; &lt;div class="lisp source-lisp" style="font-family: monospace;"&gt; &lt;pre class="de1"&gt;&lt;span class="co1"&gt;;;Without reflection&lt;/span&gt;&lt;br /&gt;&lt;span class="br0"&gt;(&lt;/span&gt;+ &lt;span class="nu0"&gt;1&lt;/span&gt; &lt;span class="nu0"&gt;2&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="co1"&gt;;;With reflection&lt;/span&gt;&lt;br /&gt;&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="kw1"&gt;eval&lt;/span&gt; '&lt;span class="br0"&gt;(&lt;/span&gt;+ &lt;span class="nu0"&gt;1&lt;/span&gt; &lt;span class="nu0"&gt;2&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt; &lt;/div&gt; &lt;h3&gt;&lt;span class="editsection"&gt;&lt;/span&gt; &lt;span class="mw-headline" id="ECMAScript"&gt;ECMAScript&lt;/span&gt;&lt;/h3&gt; &lt;p&gt;Here is an equivalent example in &lt;a href="http://en.wikipedia.org/wiki/ECMAScript" title="ECMAScript"&gt;ECMAScript&lt;/a&gt;, and therefore works in &lt;a href="http://en.wikipedia.org/wiki/JavaScript" title="JavaScript"&gt;JavaScript&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/ActionScript" title="ActionScript"&gt;ActionScript&lt;/a&gt;:&lt;/p&gt; &lt;div dir="ltr" class="mw-geshi" style="text-align: left;"&gt; &lt;div class="javascript source-javascript" style="font-family: monospace;"&gt; &lt;pre class="de1"&gt;&lt;span class="co1"&gt;// Without reflection&lt;/span&gt;&lt;br /&gt;&lt;span class="kw2"&gt;new&lt;/span&gt; Foo&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;.&lt;span class="me1"&gt;hello&lt;/span&gt;&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="co1"&gt;// With reflection&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="co1"&gt;// assuming that Foo resides in this&lt;/span&gt;&lt;br /&gt;&lt;span class="kw2"&gt;new&lt;/span&gt; &lt;span class="kw1"&gt;this&lt;/span&gt;&lt;span class="br0"&gt;[&lt;/span&gt;&lt;span class="st0"&gt;'Foo'&lt;/span&gt;&lt;span class="br0"&gt;]&lt;/span&gt;&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="br0"&gt;[&lt;/span&gt;&lt;span class="st0"&gt;'hello'&lt;/span&gt;&lt;span class="br0"&gt;]&lt;/span&gt;&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="co1"&gt;// or without assumption&lt;/span&gt;&lt;br /&gt;&lt;span class="kw2"&gt;new&lt;/span&gt; &lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="kw1"&gt;eval&lt;/span&gt;&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="st0"&gt;'Foo'&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="br0"&gt;[&lt;/span&gt;&lt;span class="st0"&gt;'hello'&lt;/span&gt;&lt;span class="br0"&gt;]&lt;/span&gt;&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt; &lt;/div&gt; &lt;h3&gt;&lt;span class="editsection"&gt;&lt;/span&gt; &lt;span class="mw-headline" id="Java"&gt;Java&lt;/span&gt;&lt;/h3&gt; &lt;p&gt;The following is an example in &lt;a href="http://en.wikipedia.org/wiki/Java_%28programming_language%29" title="Java (programming language)"&gt;Java&lt;/a&gt; using the &lt;a href="http://en.wikipedia.org/wiki/Java_package" title="Java package"&gt;Java package&lt;/a&gt; &lt;code&gt;&lt;a href="http://java.sun.com/javase/6/docs/api/java/lang/reflect/package-summary.html" class="external text" rel="nofollow"&gt;java.lang.reflect&lt;/a&gt;&lt;/code&gt;:&lt;/p&gt; &lt;div dir="ltr" class="mw-geshi" style="text-align: left;"&gt; &lt;div class="java source-java" style="font-family: monospace;"&gt; &lt;pre class="de1"&gt;&lt;span class="co1"&gt;// Without reflection&lt;/span&gt;&lt;br /&gt;Foo foo &lt;span class="sy0"&gt;=&lt;/span&gt; &lt;span class="kw1"&gt;new&lt;/span&gt; Foo&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy0"&gt;;&lt;/span&gt;&lt;br /&gt;foo.&lt;span class="me1"&gt;hello&lt;/span&gt;&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy0"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="co1"&gt;// With reflection&lt;/span&gt;&lt;br /&gt;&lt;span class="kw1"&gt;Class&lt;/span&gt; cls &lt;span class="sy0"&gt;=&lt;/span&gt; &lt;span class="kw1"&gt;Class&lt;/span&gt;.&lt;span class="me1"&gt;forName&lt;/span&gt;&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="st0"&gt;"Foo"&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy0"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="kw3"&gt;Object&lt;/span&gt; foo &lt;span class="sy0"&gt;=&lt;/span&gt; cls.&lt;span class="me1"&gt;newInstance&lt;/span&gt;&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy0"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="kw3"&gt;Method&lt;/span&gt; method &lt;span class="sy0"&gt;=&lt;/span&gt; cls.&lt;span class="me1"&gt;getMethod&lt;/span&gt;&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="st0"&gt;"hello"&lt;/span&gt;, &lt;span class="kw2"&gt;null&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy0"&gt;;&lt;/span&gt;&lt;br /&gt;method.&lt;span class="me1"&gt;invoke&lt;/span&gt;&lt;span class="br0"&gt;(&lt;/span&gt;foo, &lt;span class="kw2"&gt;null&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy0"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt; &lt;/div&gt; &lt;h3&gt;&lt;span class="editsection"&gt;&lt;/span&gt;&lt;span class="mw-headline" id="Objective_C"&gt;Objective C&lt;/span&gt;&lt;/h3&gt; &lt;p&gt;The following is an example in &lt;a href="http://en.wikipedia.org/wiki/Objective_C" title="Objective C" class="mw-redirect"&gt;Objective C&lt;/a&gt;&lt;/p&gt; &lt;div dir="ltr" class="mw-geshi" style="text-align: left;"&gt; &lt;div class="objc source-objc" style="font-family: monospace;"&gt; &lt;pre class="de1"&gt;&lt;span class="co2"&gt;// Without reflection&lt;/span&gt;&lt;br /&gt;Foo &lt;span class="sy0"&gt;*&lt;/span&gt;foo &lt;span class="sy0"&gt;=&lt;/span&gt; &lt;span class="br0"&gt;[&lt;/span&gt;&lt;span class="br0"&gt;[&lt;/span&gt;Foo alloc&lt;span class="br0"&gt;]&lt;/span&gt; init&lt;span class="br0"&gt;]&lt;/span&gt;;&lt;br /&gt;&lt;span class="br0"&gt;[&lt;/span&gt;foo hello&lt;span class="br0"&gt;]&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span class="co2"&gt;// With reflection&lt;/span&gt;&lt;br /&gt;&lt;span class="kw4"&gt;Class&lt;/span&gt; cls &lt;span class="sy0"&gt;=&lt;/span&gt; NSClassFromString&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="co3"&gt;@&lt;/span&gt;&lt;span class="st0"&gt;"Foo"&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;span class="kw4"&gt;id&lt;/span&gt; foo &lt;span class="sy0"&gt;=&lt;/span&gt; &lt;span class="br0"&gt;[&lt;/span&gt;&lt;span class="br0"&gt;[&lt;/span&gt;cls alloc&lt;span class="br0"&gt;]&lt;/span&gt; init&lt;span class="br0"&gt;]&lt;/span&gt;;&lt;br /&gt;&lt;span class="kw4"&gt;SEL&lt;/span&gt; selector &lt;span class="sy0"&gt;=&lt;/span&gt; NSSelectorFromString&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="co3"&gt;@&lt;/span&gt;&lt;span class="st0"&gt;"hello"&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;span class="br0"&gt;[&lt;/span&gt;foo performSelector&lt;span class="sy0"&gt;:&lt;/span&gt;selector withObject&lt;span class="sy0"&gt;:&lt;/span&gt;&lt;span class="kw2"&gt;nil&lt;/span&gt;&lt;span class="br0"&gt;]&lt;/span&gt;;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt; &lt;/div&gt; &lt;h3&gt;&lt;span class="editsection"&gt;&lt;/span&gt; &lt;span class="mw-headline" id="Perl"&gt;Perl&lt;/span&gt;&lt;/h3&gt; &lt;p&gt;Here is an equivalent example in &lt;a href="http://en.wikipedia.org/wiki/Perl" title="Perl"&gt;Perl&lt;/a&gt;:&lt;/p&gt; &lt;div dir="ltr" class="mw-geshi" style="text-align: left;"&gt; &lt;div class="perl source-perl" style="font-family: monospace;"&gt; &lt;pre class="de1"&gt;&lt;span class="co1"&gt;# without reflection&lt;/span&gt;&lt;br /&gt;&lt;span class="kw1"&gt;my&lt;/span&gt; &lt;span class="re0"&gt;$foo&lt;/span&gt; &lt;span class="sy0"&gt;=&lt;/span&gt; Foo&lt;span class="sy0"&gt;-&gt;&lt;/span&gt;&lt;span class="me1"&gt;new&lt;/span&gt;&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy0"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="re0"&gt;$foo&lt;/span&gt;&lt;span class="sy0"&gt;-&gt;&lt;/span&gt;&lt;span class="me1"&gt;hello&lt;/span&gt;&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy0"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="co1"&gt;# with reflection&lt;/span&gt;&lt;br /&gt;&lt;span class="kw1"&gt;my&lt;/span&gt; &lt;span class="re0"&gt;$class&lt;/span&gt;  &lt;span class="sy0"&gt;=&lt;/span&gt; &lt;span class="st0"&gt;"Foo"&lt;/span&gt;&lt;span class="sy0"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="kw1"&gt;my&lt;/span&gt; &lt;span class="re0"&gt;$method&lt;/span&gt; &lt;span class="sy0"&gt;=&lt;/span&gt; &lt;span class="st0"&gt;"hello"&lt;/span&gt;&lt;span class="sy0"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="kw1"&gt;my&lt;/span&gt; &lt;span class="re0"&gt;$object&lt;/span&gt; &lt;span class="sy0"&gt;=&lt;/span&gt; &lt;span class="re0"&gt;$class&lt;/span&gt;&lt;span class="sy0"&gt;-&gt;&lt;/span&gt;&lt;span class="me1"&gt;new&lt;/span&gt;&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy0"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="re0"&gt;$object&lt;/span&gt;&lt;span class="sy0"&gt;-&gt;&lt;/span&gt;&lt;span class="re0"&gt;$method&lt;/span&gt;&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy0"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt; &lt;/div&gt; &lt;h3&gt;&lt;span class="editsection"&gt;&lt;/span&gt;&lt;span class="mw-headline" id="PHP"&gt;PHP&lt;/span&gt;&lt;/h3&gt; &lt;p&gt;Here is an equivalent example in &lt;a href="http://en.wikipedia.org/wiki/PHP" title="PHP"&gt;PHP&lt;/a&gt;:&lt;/p&gt; &lt;div dir="ltr" class="mw-geshi" style="text-align: left;"&gt; &lt;div class="php source-php" style="font-family: monospace;"&gt; &lt;pre class="de1"&gt;&lt;span class="co1"&gt;// without reflection&lt;/span&gt;&lt;br /&gt;&lt;span class="re0"&gt;$Foo&lt;/span&gt; &lt;span class="sy0"&gt;=&lt;/span&gt; &lt;span class="kw2"&gt;new&lt;/span&gt; Foo&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy0"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="re0"&gt;$Foo&lt;/span&gt;&lt;span class="sy0"&gt;-&gt;&lt;/span&gt;&lt;span class="me1"&gt;hello&lt;/span&gt;&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy0"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="co1"&gt;// with reflection&lt;/span&gt;&lt;br /&gt;&lt;span class="re0"&gt;$f&lt;/span&gt; &lt;span class="sy0"&gt;=&lt;/span&gt; &lt;span class="kw2"&gt;new&lt;/span&gt; ReflectionClass&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="st0"&gt;"Foo"&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy0"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="re0"&gt;$m&lt;/span&gt; &lt;span class="sy0"&gt;=&lt;/span&gt; &lt;span class="re0"&gt;$f&lt;/span&gt;&lt;span class="sy0"&gt;-&gt;&lt;/span&gt;&lt;span class="me1"&gt;GetMethod&lt;/span&gt;&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="st0"&gt;"hello"&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy0"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="re0"&gt;$m&lt;/span&gt;&lt;span class="sy0"&gt;-&gt;&lt;/span&gt;&lt;span class="me1"&gt;invoke&lt;/span&gt;&lt;span class="br0"&gt;(&lt;/span&gt; &lt;span class="re0"&gt;$f&lt;/span&gt;&lt;span class="sy0"&gt;-&gt;&lt;/span&gt;&lt;span class="me1"&gt;newInstance&lt;/span&gt;&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt; &lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy0"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt; &lt;/div&gt; &lt;h3&gt;&lt;span class="editsection"&gt;&lt;/span&gt;&lt;span class="mw-headline" id="Python"&gt;Python&lt;/span&gt;&lt;/h3&gt; &lt;p&gt;Here is an equivalent example from the &lt;a href="http://en.wikipedia.org/wiki/Python_%28programming_language%29" title="Python (programming language)"&gt;Python&lt;/a&gt; shell:&lt;/p&gt; &lt;div dir="ltr" class="mw-geshi" style="text-align: left;"&gt; &lt;div class="python source-python" style="font-family: monospace;"&gt; &lt;pre class="de1"&gt;&lt;span class="sy0"&gt;&gt;&gt;&gt;&lt;/span&gt; &lt;span class="co1"&gt;# Class definition&lt;/span&gt;&lt;br /&gt;&lt;span class="sy0"&gt;&gt;&gt;&gt;&lt;/span&gt; &lt;span class="kw1"&gt;class&lt;/span&gt; Foo&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="kw2"&gt;object&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;:&lt;br /&gt;...     &lt;span class="kw1"&gt;def&lt;/span&gt; hello&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="kw2"&gt;self&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;:&lt;br /&gt;...         &lt;span class="kw1"&gt;print&lt;/span&gt; &lt;span class="st0"&gt;"Hi"&lt;/span&gt;&lt;br /&gt;...&lt;br /&gt;&lt;span class="sy0"&gt;&gt;&gt;&gt;&lt;/span&gt; &lt;span class="co1"&gt;# Instantiation&lt;/span&gt;&lt;br /&gt;&lt;span class="sy0"&gt;&gt;&gt;&gt;&lt;/span&gt; foo = Foo&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span class="sy0"&gt;&gt;&gt;&gt;&lt;/span&gt; &lt;span class="co1"&gt;# Normal call&lt;/span&gt;&lt;br /&gt;&lt;span class="sy0"&gt;&gt;&gt;&gt;&lt;/span&gt; foo.&lt;span class="me1"&gt;hello&lt;/span&gt;&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;br /&gt;Hi&lt;br /&gt;&lt;span class="sy0"&gt;&gt;&gt;&gt;&lt;/span&gt; &lt;span class="co1"&gt;# Instantiation with reflection&lt;/span&gt;&lt;br /&gt;&lt;span class="sy0"&gt;&gt;&gt;&gt;&lt;/span&gt; foo_class = &lt;span class="kw2"&gt;globals&lt;/span&gt;&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="br0"&gt;[&lt;/span&gt;&lt;span class="st0"&gt;'Foo'&lt;/span&gt;&lt;span class="br0"&gt;]&lt;/span&gt;&lt;br /&gt;&lt;span class="sy0"&gt;&gt;&gt;&gt;&lt;/span&gt; &lt;span class="co1"&gt;# Calling constructor&lt;/span&gt;&lt;br /&gt;&lt;span class="sy0"&gt;&gt;&gt;&gt;&lt;/span&gt; foo = foo_class&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span class="sy0"&gt;&gt;&gt;&gt;&lt;/span&gt; &lt;span class="co1"&gt;# Call foo's hello() method using a string for the function name&lt;/span&gt;&lt;br /&gt;&lt;span class="sy0"&gt;&gt;&gt;&gt;&lt;/span&gt; method = &lt;span class="kw2"&gt;getattr&lt;/span&gt;&lt;span class="br0"&gt;(&lt;/span&gt;foo, &lt;span class="st0"&gt;'hello'&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span class="sy0"&gt;&gt;&gt;&gt;&lt;/span&gt; method&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;br /&gt;Hi&lt;br /&gt;&lt;span class="sy0"&gt;&gt;&gt;&gt;&lt;/span&gt; &lt;span class="co1"&gt;# if class Foo defined in another module&lt;/span&gt;&lt;br /&gt;&lt;span class="sy0"&gt;&gt;&gt;&gt;&lt;/span&gt; &lt;span class="kw1"&gt;import&lt;/span&gt; models&lt;br /&gt;&lt;span class="sy0"&gt;&gt;&gt;&gt;&lt;/span&gt; foo_class = &lt;span class="kw2"&gt;getattr&lt;/span&gt;&lt;span class="br0"&gt;(&lt;/span&gt;models, &lt;span class="st0"&gt;'Foo'&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt; &lt;/div&gt; &lt;h3&gt;&lt;span class="editsection"&gt;&lt;/span&gt; &lt;span class="mw-headline" id="Ruby"&gt;Ruby&lt;/span&gt;&lt;/h3&gt; &lt;p&gt;Here is an equivalent example in &lt;a href="http://en.wikipedia.org/wiki/Ruby_%28programming_language%29" title="Ruby (programming language)"&gt;Ruby&lt;/a&gt;:&lt;/p&gt; &lt;div dir="ltr" class="mw-geshi" style="text-align: left;"&gt; &lt;div class="ruby source-ruby" style="font-family: monospace;"&gt; &lt;pre class="de1"&gt;&lt;span class="co1"&gt;# without reflection&lt;/span&gt;&lt;br /&gt;Foo.&lt;span class="me1"&gt;new&lt;/span&gt;.&lt;span class="me1"&gt;hello&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="co1"&gt;# with reflection&lt;/span&gt;&lt;br /&gt;&lt;span class="kw4"&gt;Object&lt;/span&gt;.&lt;span class="me1"&gt;const_get&lt;/span&gt;&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="re3"&gt;:Foo&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;.&lt;span class="me1"&gt;send&lt;/span&gt;&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="re3"&gt;:new&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;.&lt;span class="me1"&gt;send&lt;/span&gt;&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="re3"&gt;:hello&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt; &lt;/div&gt; &lt;h3&gt;&lt;span class="editsection"&gt;&lt;/span&gt; &lt;span class="mw-headline" id="Smalltalk"&gt;Smalltalk&lt;/span&gt;&lt;/h3&gt; &lt;p&gt;Here is an equivalent example in &lt;a href="http://en.wikipedia.org/wiki/Smalltalk" title="Smalltalk"&gt;Smalltalk&lt;/a&gt;:&lt;/p&gt; &lt;div dir="ltr" class="mw-geshi" style="text-align: left;"&gt; &lt;div class="smalltalk source-smalltalk" style="font-family: monospace;"&gt; &lt;pre class="de1"&gt;&lt;span class="coMULTI"&gt;"Without reflection"&lt;/span&gt;&lt;br /&gt;&lt;span class="re0"&gt;Foo&lt;/span&gt; new hello&lt;br /&gt;&lt;br /&gt;&lt;span class="coMULTI"&gt;"With reflection"&lt;/span&gt;&lt;br /&gt;&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="re0"&gt;Compiler&lt;/span&gt; evaluate: &lt;span class="st0"&gt;'Foo'&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt; new perform: &lt;span class="re1"&gt;#hello&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt; &lt;/div&gt; &lt;h3&gt;&lt;span class="editsection"&gt;&lt;/span&gt; &lt;span class="mw-headline" id="Io"&gt;Io&lt;/span&gt;&lt;/h3&gt; &lt;p&gt;Here is an equivalent example in &lt;a href="http://en.wikipedia.org/wiki/Io_%28programming_language%29" title="Io (programming language)"&gt;Io&lt;/a&gt;:&lt;/p&gt; &lt;div dir="ltr" class="mw-geshi" style="text-align: left;"&gt; &lt;div class="io source-io" style="font-family: monospace;"&gt; &lt;pre class="de1"&gt;Foo := &lt;span class="kw3"&gt;Object&lt;/span&gt; &lt;span class="kw2"&gt;clone&lt;/span&gt; &lt;span class="kw2"&gt;do&lt;/span&gt;&lt;span class="br0"&gt;(&lt;/span&gt;&lt;br /&gt;   hello := &lt;span class="kw2"&gt;method&lt;/span&gt;&lt;span class="br0"&gt;(&lt;/span&gt;&lt;br /&gt;       &lt;span class="st0"&gt;"Hello"&lt;/span&gt; println&lt;br /&gt;   &lt;span class="br0"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="co2"&gt;#Without reflection&lt;/span&gt;&lt;br /&gt;Foo hello&lt;br /&gt;&lt;br /&gt;&lt;span class="co2"&gt;#With reflection&lt;/span&gt;&lt;br /&gt;&lt;span class="kw2"&gt;getSlot&lt;/span&gt;&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="st0"&gt;"Foo"&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt; &lt;span class="kw2"&gt;getSlot&lt;/span&gt;&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="st0"&gt;"hello"&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt; call&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt; &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7331742083114938114-5097871632523132075?l=tadeze.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/0SNWOvwMeoE8SSqaVn4680fTgIM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/0SNWOvwMeoE8SSqaVn4680fTgIM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/0SNWOvwMeoE8SSqaVn4680fTgIM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/0SNWOvwMeoE8SSqaVn4680fTgIM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MyComputingLife/~4/_VSNH387XFk" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://tadeze.blogspot.com/feeds/5097871632523132075/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=7331742083114938114&amp;postID=5097871632523132075" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7331742083114938114/posts/default/5097871632523132075?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7331742083114938114/posts/default/5097871632523132075?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MyComputingLife/~3/_VSNH387XFk/reflection-oriented-programming.html" title="Reflection-oriented programming" /><author><name>tadesse</name><uri>http://www.blogger.com/profile/01745642569109272755</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://tadeze.blogspot.com/2010/01/reflection-oriented-programming.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkEAR3s4fCp7ImA9WxNQEUU.&quot;"><id>tag:blogger.com,1999:blog-7331742083114938114.post-1444148574373698933</id><published>2009-09-17T14:52:00.000+03:00</published><updated>2009-09-17T14:57:26.534+03:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-09-17T14:57:26.534+03:00</app:edited><title>Language Wars  </title><content type="html">Language Wars&lt;br /&gt;by Joel Spolsky&lt;br /&gt;Friday, September 01, 2006&lt;br /&gt;An old friend emailed me to ask:&lt;br /&gt;“I wanted to get your response to some basic questions concerning technologies available for creating an enterprise level application that is built upon a Web Server, Web based applications, and a large distribution model and collection model. The project is starting from scratch and so there is no legacy code involved but other than that I won't bore you with the details...&lt;br /&gt;“Would you head down the .NET route or J2EE?&lt;br /&gt;“Which Web Server (Apache, IIS, or something else) should we use and why?&lt;br /&gt;“Which Web development language (ASP.NET, Ruby, Ruby on Rails, Java, Python, etc.) would you recommend and why?&lt;br /&gt;“What do you use at your company and why?”&lt;br /&gt;Ah, an excellent question, simultaneously impossible to answer and very easy to answer!&lt;br /&gt;Sorry, I should stop speaking in riddles. A while ago I wrote an article called &lt;a href="http://www.joelonsoftware.com/articles/LordPalmerston.html"&gt;Lord Palmerston on Programming&lt;/a&gt; in which I claimed that some of these programming worlds, like .NET and Java, were so huge and complicated that you never could really tell if they were going to be good enough for your needs until it was too late. In particular, a debate between the C#/.NET/IIS stack and the Java/J2EE/Apache/Solaris stack and the PHP/Apache/Linux stack could go on and on for years and years and you'd never find the right answer. That's because there are so many pros and cons of all these platforms that advocates of each side can debate and debate and never get any closer to the Truth, but it sure as heck is a fun debate.&lt;br /&gt;You might think that if you could find someone with extensive experience in multiple platforms, they would be the right person to ask. I haven't found a lot of people like that. What I do know for sure, though, is two things:&lt;br /&gt;People all over the world are constantly building web applications using .NET, using Java, and using PHP all the time. None of them are failing because of the choice of technology.&lt;br /&gt;All of these environments are large and complex and you really need at least one architect with serious experience developing for the one you choose, because otherwise you'll do things wrong and wind up with messy code that needs to be restructured.&lt;br /&gt;Last summer when we had a &lt;a href="http://www.projectaardvark.com/"&gt;group of interns&lt;/a&gt; build &lt;a href="https://www.copilot.com/"&gt;Copilot&lt;/a&gt;, we had to decide what language to use for new code. I know that typically on new projects there's a long evaluation period where you decide what technology to use, along with lots of debates that include some crazy person actually wasting quite a lot of time evaluating &lt;a href="http://www.squeak.org/"&gt;Squeak&lt;/a&gt; and &lt;a href="http://www.findinglisp.com/blog/2005/12/reddit-and-lisp-psychosis.html"&gt;Lisp&lt;/a&gt; and &lt;a href="http://www.cabochon.com/~stevey/blog-rants/more-ocaml.html"&gt;OCaml&lt;/a&gt; and lots of other languages which are totally, truly brilliant programming languages worthy of great praise, but just don't have the gigantic ecosystem you need around them if you want to develop web software. These debates are enormously fun and a total and utter waste of time, because the bottom line is that there are three and a half platforms (C#, Java, PHP, and a half Python) that are all equally likely to make you successful, an infinity of platforms where you're pretty much guaranteed to fail spectacularly when it's too late to change anything (Lisp, ISAPI DLLs written in C, Perl), and a handful of platforms where The Jury Is Not In, So Why Take The Risk When Your Job Is On The Line? (Ruby on Rails). Before you flame me, Ruby is a beautiful language and I'm sure you can have a lot of fun developing apps it in, and in fact if you want to do something non-mission-critical, I'm sure you'll have a lot of fun, but for Serious Business Stuff you really must recognize that there just isn't a lot of experience in the world building big mission critical web systems in Ruby on Rails, and I'm really not sure that you won't hit scaling problems, or problems interfacing with some old legacy thingamabob, or problems finding programmers who can understand the code, or whatnot. So while Ruby on Rails is the fun answer and yes I've heard of 37 Signals and they're making lovely Ruby on Rails apps, and making lots of money, but that's not a safe choice for at least another year or six. I for one am scared of Ruby because (1) it displays a stunning antipathy towards &lt;a href="http://www.joelonsoftware.com/articles/Unicode.html"&gt;Unicode&lt;/a&gt; and (2) it's known to be slow, so if you become The Next MySpace, you'll be buying 5 times as many boxes as the .NET guy down the hall. Those things might eventually get fixed but for now, you can risk Ruby on your two-person dormroom startup or your senior project, not for enterprisy stuff where Someone is Going to Get Fired. Python get a half because it's on the border, about to cross the line from an "interesting" choice to a "safe" choice.&lt;br /&gt;Oh and I know &lt;a href="http://www.paulgraham.com/avg.html"&gt;Paul told you&lt;/a&gt; that he made his app in Lisp and then he made millions of dollars because he made his app in Lisp, but honestly only &lt;a href="http://www.reddit.com/"&gt;two people&lt;/a&gt; ever believed him and, a complete rewrite later, they won't make that mistake again.&lt;br /&gt;The safe answer, for the Big Enterprisy Thing where you have no interest in being on the cutting edge, is C#, Java, PHP, or Python, since there's so much evidence that when it comes right down to it zillions of people are building huge business-critical things in those languages and while they may have problems, they're not life-threatening problems.&lt;br /&gt;How do you decide between C#, Java, PHP, and Python? The only real difference is which one you know better. If you have a serious Java guru on your team who has build several large systems successfully with Java, you're going to be a hell of a lot more successful with Java than with C#, not because Java is a better language (it's not, but the differences are too minor to matter) but because he knows it better. Etc.&lt;br /&gt;What we ended up doing with the interns was just telling them that they had to build it in C# and ASP.NET. In particular, one intern, who wrote the website part of Copilot, had enough experience with ASP.NET to know what things to avoid (like viewstate) and knew to avoid the gotchas that make it impossible to have two &lt;forms&gt;in one page, etc. etc., so he did a beautiful job architecting the ASP.NET code exactly the right way to begin with so we didn't get into trouble later. And the benefit was that not one minute was spent debating the merits of programming languages, a fruitless debate if I've ever seen one.&lt;br /&gt;Finally -- as to what we use -- Copilot is C# and ASP.Net, as I mentioned, although the Windows client is written in C++. Our older in-house code is VBScript and our newer in-house code is C#. &lt;a href="http://www.fogcreek.com/FogBugz"&gt;FogBugz&lt;/a&gt; is written in Wasabi, a very advanced, functional-programming dialect of Basic with closures and lambdas and Rails-like active records that can be compiled down to VBScript, JavaScript, PHP4 or PHP5. Wasabi is a private, in-house language written by one of our best developers that is optimized specifically for developing FogBugz; the Wasabi compiler itself is written in C#.&lt;br /&gt;&lt;a title="FogBugz 7" href="http://www.fogcreek.com/fogbugz/"&gt;&lt;/a&gt;Hoorah! FogBugz 7 just shipped, and it’s a huge new release. See &lt;a href="http://www.fogcreek.com/FogBugz/WhatsNew.html"&gt;what's new&lt;/a&gt; and try the online demo today!&lt;br /&gt;Want to know more?&lt;br /&gt;You’re reading &lt;a href="http://www.joelonsoftware.com/"&gt;Joel on Software&lt;/a&gt;, stuffed with years and years of completely raving mad articles about software development, managing software teams, designing user interfaces, running successful software companies, and rubber duckies.&lt;br /&gt;About the author.&lt;br /&gt;I’m &lt;a href="http://www.joelonsoftware.com/AboutMe.html"&gt;Joel Spolsky&lt;/a&gt;, founder of &lt;a href="http://www.fogcreek.com/"&gt;Fog Creek Software&lt;/a&gt;, a New York company that proves that you can treat programmers well and still be highly profitable. Programmers get private offices, free lunch, and work 40 hours a week. Customers only pay for software if they’re delighted. We make &lt;a href="http://www.fogcreek.com/FogBugz/"&gt;FogBugz&lt;/a&gt;, an enlightened project management system designed to help great teams develop brilliant software, and &lt;a href="https://www.copilot.com/"&gt;Fog Creek Copilot&lt;/a&gt;, which makes remote desktop access easy.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7331742083114938114-1444148574373698933?l=tadeze.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/P1Bb6tYQdI-kKAQHXvCbyhEdV7E/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/P1Bb6tYQdI-kKAQHXvCbyhEdV7E/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/P1Bb6tYQdI-kKAQHXvCbyhEdV7E/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/P1Bb6tYQdI-kKAQHXvCbyhEdV7E/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MyComputingLife/~4/7tezevEDIsw" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://tadeze.blogspot.com/feeds/1444148574373698933/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=7331742083114938114&amp;postID=1444148574373698933" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7331742083114938114/posts/default/1444148574373698933?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7331742083114938114/posts/default/1444148574373698933?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MyComputingLife/~3/7tezevEDIsw/language-wars.html" title="&lt;a href=http://www.joelonsoftware.com/items/2006/09/01.html&gt;Language Wars  &lt;/a&gt;" /><author><name>tadesse</name><uri>http://www.blogger.com/profile/01745642569109272755</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://tadeze.blogspot.com/2009/09/language-wars.html</feedburner:origLink></entry></feed>

