<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Family, Working ...</title>
	<atom:link href="http://luongthanhbinh.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://luongthanhbinh.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Thu, 14 Jun 2007 03:04:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='luongthanhbinh.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Family, Working ...</title>
		<link>http://luongthanhbinh.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://luongthanhbinh.wordpress.com/osd.xml" title="Family, Working ..." />
	<atom:link rel='hub' href='http://luongthanhbinh.wordpress.com/?pushpress=hub'/>
		<item>
		<title>TKB HK1(2007-2008) KHÓA 10 &#8211; HỆ VĂN BẰNG 2 CHÍNH QUY</title>
		<link>http://luongthanhbinh.wordpress.com/2007/06/14/tkb-hk12007-2008-khoa-10-h%e1%bb%86-van-b%e1%ba%b0ng-2-chinh-quy/</link>
		<comments>http://luongthanhbinh.wordpress.com/2007/06/14/tkb-hk12007-2008-khoa-10-h%e1%bb%86-van-b%e1%ba%b0ng-2-chinh-quy/#comments</comments>
		<pubDate>Thu, 14 Jun 2007 02:55:25 +0000</pubDate>
		<dc:creator>luongthanhbinh</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://luongthanhbinh.wordpress.com/2007/06/14/tkb-hk12007-2008-khoa-10-h%e1%bb%86-van-b%e1%ba%b0ng-2-chinh-quy/</guid>
		<description><![CDATA[Lớp : NH3 Hoc lý thuyết 11/06/2007 &#8211; 07/11/2007 (21 tuần) Nghỉ hè 23/07/2007 &#8211; 03/09/2007 (06 tuần Giờ học 4 tiết/buổi. Buổi sáng :07g15 Buổi chiều : 13g00. Buổi tối : 17g45 TKB HK1(2007-2008) KHÓA 10 &#8211; HỆ VĂN BẰNG 2 CHÍNH QUY<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=luongthanhbinh.wordpress.com&amp;blog=1084690&amp;post=27&amp;subd=luongthanhbinh&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Lớp : NH3</strong></p>
<table class="MsoTableGrid" style="border:medium none;border-collapse:collapse;" border="1" cellpadding="0" cellspacing="0">
<tr>
<td style="border:1pt solid black;width:100.6pt;padding:0 5.4pt;" valign="top" width="134">
<p class="MsoNormal"><span style="font-size:11pt;font-family:'Arial','sans-serif';">Hoc lý thuyết</span></p>
</td>
<td style="width:219.8pt;border-color:black black black #000000;border-style:solid solid solid none;border-width:1pt 1pt 1pt medium;padding:0 5.4pt;" valign="top" width="293">
<p class="MsoNormal"><span style="font-size:11pt;font-family:'Arial','sans-serif';">11/06/2007   &#8211; 07/11/2007 (21 tuần)</span></p>
</td>
</tr>
<tr>
<td style="width:100.6pt;border-color:#000000 black black;border-style:none solid solid;border-width:medium 1pt 1pt;padding:0 5.4pt;" valign="top" width="134">
<p class="MsoNormal"><span style="font-size:11pt;font-family:'Arial','sans-serif';">Nghỉ   hè               </span></p>
</td>
<td style="width:219.8pt;border-style:none solid solid none;border-width:medium 1pt 1pt medium;padding:0 5.4pt;" valign="top" width="293">
<p class="MsoNormal"><span style="font-size:11pt;font-family:'Arial','sans-serif';">23/07/2007   &#8211; 03/09/2007 (06 tuần</span></p>
</td>
</tr>
<tr>
<td style="width:100.6pt;border-color:#000000 black black;border-style:none solid solid;border-width:medium 1pt 1pt;padding:0 5.4pt;" valign="top" width="134">
<p class="MsoNormal"><span style="font-size:11pt;font-family:'Arial','sans-serif';">Giờ   học              </span></p>
</td>
<td style="width:219.8pt;border-style:none solid solid none;border-width:medium 1pt 1pt medium;padding:0 5.4pt;" valign="top" width="293">
<p class="MsoNormal"><span style="font-size:11pt;font-family:'Arial','sans-serif';">4   tiết/buổi.</span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:'Arial','sans-serif';"><span>            </span>Buổi sáng <span> </span>:07g15</span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:'Arial','sans-serif';"><span></span>Buổi chiều : 13g00.</span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:'Arial','sans-serif';"><span>            </span><span> </span>Buổi tối <span>    </span>: 17g45</span></p>
</td>
</tr>
</table>
<h1 align="left"></h1>
<p><a href="http://luongthanhbinh.files.wordpress.com/2007/06/thoi-khoa-bieu-hoc-ky-i-nh-2007-2008-khoa-10-he-van-bang-2.doc" title="TKB HK1(2007-2008) KHÓA 10 - HỆ VĂN BẰNG 2 CHÍNH QUY">TKB HK1(2007-2008) KHÓA 10 &#8211; HỆ VĂN BẰNG 2 CHÍNH QUY</a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/luongthanhbinh.wordpress.com/27/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/luongthanhbinh.wordpress.com/27/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/luongthanhbinh.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/luongthanhbinh.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/luongthanhbinh.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/luongthanhbinh.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/luongthanhbinh.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/luongthanhbinh.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/luongthanhbinh.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/luongthanhbinh.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/luongthanhbinh.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/luongthanhbinh.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/luongthanhbinh.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/luongthanhbinh.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/luongthanhbinh.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/luongthanhbinh.wordpress.com/27/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=luongthanhbinh.wordpress.com&amp;blog=1084690&amp;post=27&amp;subd=luongthanhbinh&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://luongthanhbinh.wordpress.com/2007/06/14/tkb-hk12007-2008-khoa-10-h%e1%bb%86-van-b%e1%ba%b0ng-2-chinh-quy/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bc1f87bb951c7777ded1b18b9db08755?s=96&#38;d=identicon" medium="image">
			<media:title type="html">luongthanhbinh</media:title>
		</media:content>
	</item>
		<item>
		<title>Chat Thanh</title>
		<link>http://luongthanhbinh.wordpress.com/2007/06/07/chat-thanh/</link>
		<comments>http://luongthanhbinh.wordpress.com/2007/06/07/chat-thanh/#comments</comments>
		<pubDate>Thu, 07 Jun 2007 07:01:17 +0000</pubDate>
		<dc:creator>luongthanhbinh</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://luongthanhbinh.wordpress.com/2007/06/07/chat-thanh/</guid>
		<description><![CDATA[dndthanh: khổ thế đó dndthanh: bé gái nên làm vệ sinh fải cẩn thận dndthanh: lúc nào ranh search &#8220;vệ sinh bé gái&#8221; mà xem cho kỹ hơn dndthanh: chuyen pha sua cho bé cũng thế Binh Luong: chi hay coi link nao Binh Luong: cho em link voi dndthanh: em fải để ý, bình [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=luongthanhbinh.wordpress.com&amp;blog=1084690&amp;post=25&amp;subd=luongthanhbinh&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>dndthanh: khổ thế đó<br />
dndthanh: bé gái nên làm vệ sinh fải cẩn thận<br />
dndthanh: lúc nào ranh search &#8220;vệ sinh bé gái&#8221; mà xem cho kỹ hơn<br />
dndthanh: chuyen pha sua cho bé cũng thế<br />
Binh Luong: chi hay coi link nao<br />
Binh Luong: cho em link voi<br />
dndthanh: em fải để ý, bình fải sạch 0 là bé dễ đau bụng,<br />
dndthanh: pha sữa ngoai thì nứơc vừa đủ, nứơc dư là bé 0 đu chất, mà nước thiếu sẽ bị bón, fải chính xác<br />
dndthanh: chi hay xem www.webtretho.com hay www.lamchame.com<br />
dndthanh: ngoai ra thi searh<br />
dndthanh has signed back in. (6/7/2007 12:36 PM)</p>
<p>dndthanh: em xem cach lau cho bé gái và bé trai nè http://72.14.235.104/search?q=cache:d6mmbUWsvUQJ:www.webtretho.com/news/item_detail.php%3Fc_id%3D23400%26item_id%3D1382+%22b%C3%A9+g%C3%A1i%22+%2B%22lau%22&amp;hl=vi&amp;ct=clnk&amp;cd=1&amp;gl=vn<br />
dndthanh: bà và mẹ nghiên cuứ, tắm cho bé được thì tốt http://www.cpv.org.vn/details.asp?topic=165&amp;subtopic=352&amp;leader_topic=857&amp;id=BT1120775487</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/luongthanhbinh.wordpress.com/25/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/luongthanhbinh.wordpress.com/25/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/luongthanhbinh.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/luongthanhbinh.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/luongthanhbinh.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/luongthanhbinh.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/luongthanhbinh.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/luongthanhbinh.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/luongthanhbinh.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/luongthanhbinh.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/luongthanhbinh.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/luongthanhbinh.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/luongthanhbinh.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/luongthanhbinh.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/luongthanhbinh.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/luongthanhbinh.wordpress.com/25/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=luongthanhbinh.wordpress.com&amp;blog=1084690&amp;post=25&amp;subd=luongthanhbinh&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://luongthanhbinh.wordpress.com/2007/06/07/chat-thanh/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bc1f87bb951c7777ded1b18b9db08755?s=96&#38;d=identicon" medium="image">
			<media:title type="html">luongthanhbinh</media:title>
		</media:content>
	</item>
		<item>
		<title>NHibernate and Domain Driven Design</title>
		<link>http://luongthanhbinh.wordpress.com/2007/06/03/nhibernate-and-domain-driven-design/</link>
		<comments>http://luongthanhbinh.wordpress.com/2007/06/03/nhibernate-and-domain-driven-design/#comments</comments>
		<pubDate>Sun, 03 Jun 2007 10:11:15 +0000</pubDate>
		<dc:creator>luongthanhbinh</dc:creator>
				<category><![CDATA[NHibernate]]></category>

		<guid isPermaLink="false">http://luongthanhbinh.wordpress.com/2007/06/03/nhibernate-and-domain-driven-design/</guid>
		<description><![CDATA[Ben Scheirman wrote a series of articles about NHibernate and Domain Driven Design. A Journey with NHibernate &#8211; Part 1 A Journey With NHibernate &#8211; Part 2 A Journey With NHibernate (and DDD) &#8211; Part 3 A Journey with Domain Driven Design (and NHibernate) &#8211; Part 4 A Journey with Domain Driven Design (and NHibernate) [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=luongthanhbinh.wordpress.com&amp;blog=1084690&amp;post=24&amp;subd=luongthanhbinh&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p> <a href="http://www.flux88.com/" target="_blank">Ben Scheirman</a> wrote a series of articles about NHibernate and Domain Driven Design.</p>
<p><a href="http://www.flux88.com/2006/07/05/A+Journey+With+NHibernate++Part+1.aspx" target="_blank" class="TitleLinkStyle">A Journey with NHibernate &#8211; Part 1</a><br />
<a href="http://www.flux88.com/2006/07/10/A+Journey+With+NHibernate++Part+2.aspx" target="_blank" class="TitleLinkStyle">A Journey With NHibernate &#8211; Part 2</a><br />
<a href="http://www.flux88.com/2006/07/20/A+Journey+With+NHibernate+And+DDD++Part+3.aspx" target="_blank" class="TitleLinkStyle">A Journey With NHibernate (and DDD) &#8211; Part 3</a><br />
<a href="http://www.flux88.com/2006/07/23/A+Journey+With+Domain+Driven+Design+And+NHibernate++Part+4.aspx" target="_blank" class="TitleLinkStyle">A Journey with Domain Driven Design (and NHibernate) &#8211; Part 4</a><br />
<a href="http://www.flux88.com/2006/08/24/A+Journey+With+Domain+Driven+Design+And+NHibernate++Part+5.aspx" target="_blank" class="TitleLinkStyle">A Journey with Domain Driven Design (and NHibernate) &#8211; Part 5</a><br />
<a href="http://www.flux88.com/2006/09/02/A+Journey+With+Domain+Driven+Design+And+NHibernate++Part+6.aspx" target="_blank" class="TitleLinkStyle">A Journey with Domain Driven Design (and NHibernate) &#8211; Part 6</a><br />
<a href="http://www.flux88.com/2006/11/14/A+Journey+With+Domain+Driven+Design+And+NHibernate++Part+7.aspx" target="_blank" class="TitleLinkStyle">A Journey with Domain Driven Design (and NHibernate) &#8211; Part 7</a><br />
<a href="http://supinfo-projects.com/en/2006/nhibernate-introduction/conclusion/">http://supinfo-projects.com/en/2006/nhibernate-introduction/conclusion/<br />
</a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/luongthanhbinh.wordpress.com/24/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/luongthanhbinh.wordpress.com/24/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/luongthanhbinh.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/luongthanhbinh.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/luongthanhbinh.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/luongthanhbinh.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/luongthanhbinh.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/luongthanhbinh.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/luongthanhbinh.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/luongthanhbinh.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/luongthanhbinh.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/luongthanhbinh.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/luongthanhbinh.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/luongthanhbinh.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/luongthanhbinh.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/luongthanhbinh.wordpress.com/24/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=luongthanhbinh.wordpress.com&amp;blog=1084690&amp;post=24&amp;subd=luongthanhbinh&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://luongthanhbinh.wordpress.com/2007/06/03/nhibernate-and-domain-driven-design/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bc1f87bb951c7777ded1b18b9db08755?s=96&#38;d=identicon" medium="image">
			<media:title type="html">luongthanhbinh</media:title>
		</media:content>
	</item>
		<item>
		<title>Five Reasons for using an O/R mapping tool</title>
		<link>http://luongthanhbinh.wordpress.com/2007/06/03/five-reasons-for-using-an-or-mapping-tool/</link>
		<comments>http://luongthanhbinh.wordpress.com/2007/06/03/five-reasons-for-using-an-or-mapping-tool/#comments</comments>
		<pubDate>Sun, 03 Jun 2007 09:38:55 +0000</pubDate>
		<dc:creator>luongthanhbinh</dc:creator>
				<category><![CDATA[.net]]></category>

		<guid isPermaLink="false">http://luongthanhbinh.wordpress.com/2007/06/03/23/</guid>
		<description><![CDATA[So, why should you use any O/R mapping tool? I am not talking about a specific tool but rather all O/R mapping tools in general. There are a number of reasons for using an O/R mapping tool but before I dive into that, let me give you a brief overview of what an O/R mapping [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=luongthanhbinh.wordpress.com&amp;blog=1084690&amp;post=23&amp;subd=luongthanhbinh&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="clsDetailNewsText">
<p class="MsoBodyText" style="margin:0;"><span style="font-size:10pt;font-family:Verdana;">So, why should you use any O/R mapping tool? I am not talking about a specific tool but rather all O/R mapping tools in general. There are a number of reasons for using an O/R mapping tool but before I dive into that, let me give you a brief overview of what an O/R mapping tool really is.</span></p>
<p class="MsoBodyText" style="margin:0;"><span style="font-size:10pt;font-family:Verdana;">An O/R mapping tool generates persistence objects for your .NET application. It is a modeling and code generation tool that connects to your database and reads its schema, then lets you map objects to database tables and views, specify single-row insert, update, load, and delete operations, queries and stored procedure calls, as methods to these objects. And, it also lets you define one-to-one, one-to-many, many-to-one, and many-to-many relationships between objects based on relationships between tables in the database. It then generates fully working persistence objects code for you.</span></p>
<p class="MsoBodyText" style="margin:0;"><span style="font-size:10pt;font-family:Verdana;">There are many other features that a good O/R mapping tool provides but I’m keeping my description brief so I can talk more about the benefits.</span></p>
<p class="MsoBodyText" style="margin:0;"><strong><span style="font-family:Arial;"><font size="3">Reason 1: Cuts down your development time </font></span></strong></p>
<p class="MsoBodyText" style="margin:0;"><span style="font-size:10pt;font-family:Verdana;">First benefit of an O/R mapping tool is that it saves you a ton of development time (20% to 50% time depending on your situation). Now, O/R mapping tool is not generating any “rocket science” code for you and you could definitely do it manually if you wanted. But, this is a lot of tedious work and you would definitely be happier if you didn’t have to do it yourself. Let’s do some simple math.</span></p>
<p class="MsoBodyText" style="margin:0;"><span style="font-size:10pt;font-family:Verdana;">A typical application with 15-20 database tables has 30-50 objects (including domain and factory objects) and this is roughly 5000 to 10,000 lines of code. It is likely to take you a few weeks to a couple of months to develop and test this code. And, if your application has more tables than this (which many do), then just multiple the above numbers by that much.</span></p>
<p class="MsoBodyText" style="margin:0;"><span style="font-size:10pt;font-family:Verdana;">On the other hand, an O/R Mapping tool would generate this code for you in a day or two. Even here, you need these 1-2 days primarily to determine your object mappings to the database. The actual code generation is instantaneous. So, your time saving is tremendous.</span></p>
<p class="MsoBodyText" style="margin:0;"><strong><span style="font-family:Arial;"><font size="3">Reason 2: Produces better designed code </font></span></strong></p>
<p class="MsoBodyText" style="margin:0;"><span style="font-size:10pt;font-family:Verdana;">Second benefit of an O/R mapping tool is that it lets you produce better designed code than doing it yourself by-hand. I know what you’re thinking. You think you can do a better job than an O/R mapping tool because you write every aspect of your code. Some of you definitely can but not everyone. Consider this. An average development team has different levels of expertise and experience and not everybody is a good designer. As a result, they may not follow design patterns in their code and end up with a lesser quality code. And, if multiple developers are writing code, their code is very likely going to be inconsistent with each other. And, inconsistency itself is a big source of poor quality in an application’s code.</span></p>
<p class="MsoBodyText" style="margin:0;"><span style="font-size:10pt;font-family:Verdana;">On the other hand, a good O/R mapping tool uses code templates that have excellent design because they are very likely designed and created by very senior (architect level) engineers. And, these code templates almost always follow known design patterns. So, the code that you’ll generate from an O/R mapping tool is very likely going to be better designed than code designed by your own development team.</span></p>
<p class="MsoBodyText" style="margin:0;"><strong><span style="font-family:Arial;"><font size="3">Reason 3: You don’t have to be a .NET expert </font></span></strong></p>
<p class="MsoBodyText" style="margin:0;"><span style="font-size:10pt;font-family:Verdana;">Third benefit of using an O/R mapping tool is that you don’t have to be a .NET expert to develop your persistence code. As you know, data access code is critical for the overall performance of your application. If this code is designed and developed poorly, it can severely affect your application. So, if you developed this code by hand, you need to be an export of .NET, COM+, stateless components, and MTS.</span></p>
<p class="MsoBodyText" style="margin:0;"><span style="font-size:10pt;font-family:Verdana;">However, if you use an O/R mapping tool, you can focus primarily on the “logical design” of your persistence objects including object mapping and the different types of interactions with the database including insert, update, load, delete, queries, stored procedure calls, relationships, and more. And, the O/R mapping tool would do the rest for it. It would ensure that the generated code follows all the best practices of writing stateless .NET components to run in COM+ and MTS.</span></p>
<p class="MsoBodyText" style="margin:0;"><strong><span style="font-family:Arial;"><font size="3">Reason 4: Saves you testing time </font></span></strong></p>
<p class="MsoBodyText" style="margin:0;"><span style="font-size:10pt;font-family:Verdana;">Fourth benefit of an O/R mapping tool is that it reduces your testing effort dramatically. If you developed all the persistence code by hand, you would also be responsible for testing it yourself. And, as you know, testing is as much effort as development in any project.</span></p>
<p class="MsoBodyText" style="margin:0;"><span style="font-size:10pt;font-family:Verdana;">On the other hand, if you generated code from an O/R mapping tool, it is coming from code templates that are very likely thoroughly tested by the software vendor itself (more so than you because it is their primary focus). And, on top of it, most likely hundreds or perhaps thousands of other customers are using this tool and have tested the code generated from this O/R mapping tool. As a result, many of the bugs that you might not find in your own testing have already been found and fixed in the generated code of an O/R mapping tool.</span></p>
<p class="MsoBodyText" style="margin:0;"><strong><span style="font-family:Arial;"><font size="3">Reason 5: Simplifies your .NET development </font></span></strong></p>
<p class="MsoBodyText" style="margin:0;"><span style="font-size:10pt;font-family:Verdana;">If you have to write all the persistence code yourself, you’re bogged down into the details of ADO.NET, COM+, MTS, stateless .NET components, and more. And, you end up spending a lot of time in details that you really don’t need to. On the other hand, if you generate code from an O/R mapping tool, you get well design objects and you only need to deal with their public interface.</span></p>
<p class="MsoBodyText" style="margin:0;"><span style="font-size:10pt;font-family:Verdana;">Below is an example of code you’ll write if you used an O/R mapping tool.</span></p>
<p class="MsoNormal" style="margin:0 0 0 0.5in;"><span style="font-size:10pt;color:blue;font-family:'Courier New';">try</span><span style="font-size:10pt;font-family:'Courier New';"> { </span></p>
<p class="MsoNormal" style="margin:0 0 0 0.5in;"><span style="font-size:10pt;font-family:'Courier New';"><font face="Courier New"><span>      </span>Employees objInfo = <span style="color:blue;">new</span> Employees();<span>      </span><br />
EmployeesFactory objFactory = <span style="color:blue;">new</span> EmployeesFactory();</font></span></p>
<p class="MsoNormal" style="margin:0 0 0 0.5in;"><span style="font-size:10pt;font-family:'Courier New';">      objInfo.EmployeeID = EmployeeID; <font face="Courier New"><span>   </span><br />
objFactory.Load(objInfo); </font></span></p>
<p class="MsoNormal" style="margin:0 0 0 0.5in;"><span style="font-size:10pt;font-family:'Courier New';"><font face="Courier New"><span>      </span>// code here to use the “objInfo” object<br />
}  </font></span><span></span><span style="font-size:10pt;color:blue;font-family:'Courier New';"><br />
catch</span><span style="font-size:10pt;font-family:'Courier New';">(Exception ex) { </span></p>
<p class="MsoNormal" style="margin:0 0 0 0.5in;"><span style="font-size:10pt;font-family:'Courier New';"><font face="Courier New"><span>      </span>// code here to handle the exception <span>     </span><br />
<span style="color:blue;">return</span>;<span>     </span><br />
}</font></span></p>
<p class="MsoBodyText" style="margin:0;"><span style="font-size:10pt;font-family:Verdana;">As you can see, the generated code is very simple to use than actually writing the .NET components yourself.</span></p>
<p class="clsDetailNewsText"><span style="font-size:10pt;font-family:Verdana;">Many people have never heard of O/R mapping tools and many more have heard of them but are afraid to use them. I hope I have made a strong enough case here for you to give a serious consideration to O/R mapping for your project.</span></p>
<p class="clsDetailNewsText">&nbsp;</p>
<p class="clsDetailNewsText">From :</p>
<p> <a href="http://www.dnzone.com/ShowDetail.asp?NewsId=1276">http://www.dnzone.com/ShowDetail.asp?NewsId=1276</a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/luongthanhbinh.wordpress.com/23/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/luongthanhbinh.wordpress.com/23/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/luongthanhbinh.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/luongthanhbinh.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/luongthanhbinh.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/luongthanhbinh.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/luongthanhbinh.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/luongthanhbinh.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/luongthanhbinh.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/luongthanhbinh.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/luongthanhbinh.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/luongthanhbinh.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/luongthanhbinh.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/luongthanhbinh.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/luongthanhbinh.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/luongthanhbinh.wordpress.com/23/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=luongthanhbinh.wordpress.com&amp;blog=1084690&amp;post=23&amp;subd=luongthanhbinh&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://luongthanhbinh.wordpress.com/2007/06/03/five-reasons-for-using-an-or-mapping-tool/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bc1f87bb951c7777ded1b18b9db08755?s=96&#38;d=identicon" medium="image">
			<media:title type="html">luongthanhbinh</media:title>
		</media:content>
	</item>
		<item>
		<title>Chiêu Quân ra đời rồi, hình Chiêu Quân nè&#8230;</title>
		<link>http://luongthanhbinh.wordpress.com/2007/05/30/chieu-quan-ra-d%e1%bb%9di-r%e1%bb%93i-hinh-chieu-quan-ne/</link>
		<comments>http://luongthanhbinh.wordpress.com/2007/05/30/chieu-quan-ra-d%e1%bb%9di-r%e1%bb%93i-hinh-chieu-quan-ne/#comments</comments>
		<pubDate>Wed, 30 May 2007 15:11:34 +0000</pubDate>
		<dc:creator>luongthanhbinh</dc:creator>
				<category><![CDATA[Photo]]></category>

		<guid isPermaLink="false">http://luongthanhbinh.wordpress.com/2007/05/30/chieu-quan-ra-d%e1%bb%9di-r%e1%bb%93i-hinh-chieu-quan-ne/</guid>
		<description><![CDATA[Chiêu Quân ra đời ngày 29/05/2007 lúc 22h, tại Khoa sản Đại học Y Duợc TPHCM. Hiện đang nằm ở phòng 204 với mẹ Chiêu Quân.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=luongthanhbinh.wordpress.com&amp;blog=1084690&amp;post=17&amp;subd=luongthanhbinh&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Chiêu Quân ra đời ngày 29/05/2007  lúc 22h, tại Khoa sản Đại học Y Duợc TPHCM.   Hiện đang nằm ở phòng 204 với mẹ Chiêu Quân.</p>
<p><code><embed src='http://apps.rockyou.com/rockyou.swf?instanceid=71071021&ver=102906' quality='high'  salign='lt' width='450' height='338' wmode='transparent' name='rockyou' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /><br /><a target='_blank' href='http://www.rockyou.com/slideshow-create.php?refid=71071021'><img title='RockYou slideshow' src='http://apps.rockyou.com/images/logo-mini.gif' style='display:inline;' border='0' /></a> | <a target='_blank' alt='Comment, Add to Favorite' href='http://www.rockyou.com/show_my_gallery.php?instanceid=71071021'>View Show</a> | <a target='_blank' href='http://www.rockyou.com/slideshow-create.php?refid=71071021'>Create Your Own</a></code></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/luongthanhbinh.wordpress.com/17/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/luongthanhbinh.wordpress.com/17/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/luongthanhbinh.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/luongthanhbinh.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/luongthanhbinh.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/luongthanhbinh.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/luongthanhbinh.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/luongthanhbinh.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/luongthanhbinh.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/luongthanhbinh.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/luongthanhbinh.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/luongthanhbinh.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/luongthanhbinh.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/luongthanhbinh.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/luongthanhbinh.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/luongthanhbinh.wordpress.com/17/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=luongthanhbinh.wordpress.com&amp;blog=1084690&amp;post=17&amp;subd=luongthanhbinh&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://luongthanhbinh.wordpress.com/2007/05/30/chieu-quan-ra-d%e1%bb%9di-r%e1%bb%93i-hinh-chieu-quan-ne/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bc1f87bb951c7777ded1b18b9db08755?s=96&#38;d=identicon" medium="image">
			<media:title type="html">luongthanhbinh</media:title>
		</media:content>
	</item>
		<item>
		<title>Creating a DataTable from an IList returned from the data mapper</title>
		<link>http://luongthanhbinh.wordpress.com/2007/05/23/creating-a-datatable-from-an-ilist-returned-from-the-data-mapper/</link>
		<comments>http://luongthanhbinh.wordpress.com/2007/05/23/creating-a-datatable-from-an-ilist-returned-from-the-data-mapper/#comments</comments>
		<pubDate>Wed, 23 May 2007 08:51:32 +0000</pubDate>
		<dc:creator>luongthanhbinh</dc:creator>
				<category><![CDATA[.net]]></category>

		<guid isPermaLink="false">http://luongthanhbinh.wordpress.com/2007/05/23/creating-a-datatable-from-an-ilist-returned-from-the-data-mapper/</guid>
		<description><![CDATA[Riccardo d&#8217;Errico Sat, 15 Jul 2006 09:55:47 -0700 It arrived to me to have to convert back to a DataTable the IList result I get from the DataMapper instance. This is mainly because some asp.net components accepts binding only to dataset or datatable Here is the code I use if somebody has the same problem. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=luongthanhbinh.wordpress.com&amp;blog=1084690&amp;post=16&amp;subd=luongthanhbinh&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="msgHead"><span class="sender">Riccardo d&#8217;Errico</span><br />
<span class="date">Sat, 15 Jul 2006 09:55:47 -0700</span></p>
<p><!--X-Subject-Header-End--><!--X-Head-of-Message--><!--X-Head-of-Message-End--><!--X-Head-Body-Sep-Begin--> <!--X-Head-Body-Sep-End-->     <!--X-Body-of-Message-->It arrived to me to have to convert back to a DataTable the IList result I get from the DataMapper instance.</p>
<p>This is mainly because some <a href="http://asp.net/" rel="nofollow">asp.net</a> components accepts binding only to dataset or datatable</p>
<p>Here is the code I use if somebody has the same problem.</p>
<p>This code only works in .Net 2.0</p>
<p><font color="#0000ff" size="2">public</font><font size="2"> </font><font color="#0000ff" size="2">static</font><font size="2"> </font><font color="#008080" size="2">DataTable</font><font size="2"> GetDataTableFromIList&lt;T&gt;( </font><font color="#008080" size="2">List</font><font size="2">&lt;T&gt; aIList)</font></p>
<p><font size="2">{</font></p>
<p><font color="#008080" size="2">DataTable</font><font size="2"> _returnTable = </font><font color="#0000ff" size="2">new</font><font size="2"> </font><font color="#008080" size="2">DataTable</font><font size="2">();</font></p>
<p><font color="#0000ff" size="2">if</font><font size="2"> (aIList.Count&gt;0)</font></p>
<p>{</p>
<p><font color="#008000" size="2">//Creates the table structure looping in the in the first element of the list</font></p>
<p><font size="2"> </font><font color="#0000ff" size="2">object</font><font size="2"> _baseObj = aIList[0]; </font><font color="#008080" size="2">Type</font><font size="2"> objectType = _baseObj.GetType(); </font><font color="#008080" size="2">PropertyInfo</font><font size="2">[] properties = objectType.GetProperties(); </font><font color="#008080" size="2">DataColumn</font><font size="2"> _col;  </font><font color="#0000ff" size="2">foreach</font><font size="2"> (</font><font color="#008080" size="2">PropertyInfo</font><font size="2"> property </font><font color="#0000ff" size="2">in</font><font size="2">  properties){</font></p>
<p><font size="2">_col =</font></p>
<p><font color="#0000ff" size="2">new</font><font size="2"> </font><font color="#008080" size="2">DataColumn</font><font size="2">();_col.ColumnName = (</font></p>
<p><font color="#0000ff" size="2">string</font><font size="2">)property.Name;_col.DataType = property.PropertyType;</font></p>
<p><font size="2">_returnTable.Columns.Add(_col);</font></p>
<p><font size="2">}</font></p>
<p><font color="#008000" size="2">//Adds the rows to the table</font><font size="2"> </font><font color="#008080" size="2">DataRow</font><font size="2"> _row; </font><font color="#0000ff" size="2">foreach</font><font size="2"> (</font><font color="#0000ff" size="2">object</font><font size="2"> objItem </font><font color="#0000ff" size="2">in</font><font size="2"> aIList){</font></p>
<p><font size="2">_row = _returnTable.NewRow();</font></p>
<p><font color="#0000ff" size="2">foreach</font><font size="2"> (</font><font color="#008080" size="2">PropertyInfo</font><font size="2"> property </font><font color="#0000ff" size="2">in</font><font size="2">  properties){</font></p>
<p><font size="2">_row[property.Name] = property.GetValue(objItem,</font></p>
<p><font color="#0000ff" size="2">null</font><font size="2">);}</font></p>
<p><font size="2">_returnTable.Rows.Add(_row);</font></p>
<p><font size="2">}</font></p>
<p><font size="2">}</font></p>
<p><font color="#0000ff" size="2">return</font><font size="2"> _returnTable;}</font></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/luongthanhbinh.wordpress.com/16/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/luongthanhbinh.wordpress.com/16/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/luongthanhbinh.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/luongthanhbinh.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/luongthanhbinh.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/luongthanhbinh.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/luongthanhbinh.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/luongthanhbinh.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/luongthanhbinh.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/luongthanhbinh.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/luongthanhbinh.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/luongthanhbinh.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/luongthanhbinh.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/luongthanhbinh.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/luongthanhbinh.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/luongthanhbinh.wordpress.com/16/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=luongthanhbinh.wordpress.com&amp;blog=1084690&amp;post=16&amp;subd=luongthanhbinh&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://luongthanhbinh.wordpress.com/2007/05/23/creating-a-datatable-from-an-ilist-returned-from-the-data-mapper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bc1f87bb951c7777ded1b18b9db08755?s=96&#38;d=identicon" medium="image">
			<media:title type="html">luongthanhbinh</media:title>
		</media:content>
	</item>
		<item>
		<title>Dinh dưỡng cho sản phụ</title>
		<link>http://luongthanhbinh.wordpress.com/2007/05/18/dinh-d%c6%b0%e1%bb%a1ng-cho-s%e1%ba%a3n-ph%e1%bb%a5/</link>
		<comments>http://luongthanhbinh.wordpress.com/2007/05/18/dinh-d%c6%b0%e1%bb%a1ng-cho-s%e1%ba%a3n-ph%e1%bb%a5/#comments</comments>
		<pubDate>Fri, 18 May 2007 02:57:55 +0000</pubDate>
		<dc:creator>luongthanhbinh</dc:creator>
				<category><![CDATA[Family]]></category>

		<guid isPermaLink="false">http://luongthanhbinh.wordpress.com/2007/05/18/dinh-d%c6%b0%e1%bb%a1ng-cho-s%e1%ba%a3n-ph%e1%bb%a5/</guid>
		<description><![CDATA[1. Móng heo hầm táo đỏ : có tác dụng lợi sửa Mua móng heo (đỡ ngấy hơn giò) về hầm cho gần mềm, cho táo đỏ (loại còn hột) vào chừng 10p cho tiếp bạch quả vào hầm, tất cả cũng mềm thì nếm tí xíu muối, tí xíu duocng vào sao cho vua [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=luongthanhbinh.wordpress.com&amp;blog=1084690&amp;post=14&amp;subd=luongthanhbinh&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="font-weight:bold;">1. Móng heo hầm táo đỏ </span>: có tác dụng lợi sửa</p>
<p>Mua móng heo (đỡ ngấy hơn giò) về hầm cho gần mềm, cho táo đỏ (loại còn hột) vào chừng 10p cho tiếp bạch quả vào hầm, tất cả cũng mềm thì nếm tí xíu muối, tí xíu duocng vào sao cho vua an (an 1 mình, 0 an voi com dau) la duoc</p>
<p><span style="font-weight:bold;"> 2. Bạch quả : </span>Co tác dung lam be sổ sữa hơn, đồng thời bổ não cho bé<br />
Bạch qua có vỏ máu tráng giống như hạt dẻ, lấy đồ đập thịt bò, đập bể vỏ, chỉ lấy phần thịt bên trong</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/luongthanhbinh.wordpress.com/14/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/luongthanhbinh.wordpress.com/14/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/luongthanhbinh.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/luongthanhbinh.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/luongthanhbinh.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/luongthanhbinh.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/luongthanhbinh.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/luongthanhbinh.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/luongthanhbinh.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/luongthanhbinh.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/luongthanhbinh.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/luongthanhbinh.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/luongthanhbinh.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/luongthanhbinh.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/luongthanhbinh.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/luongthanhbinh.wordpress.com/14/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=luongthanhbinh.wordpress.com&amp;blog=1084690&amp;post=14&amp;subd=luongthanhbinh&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://luongthanhbinh.wordpress.com/2007/05/18/dinh-d%c6%b0%e1%bb%a1ng-cho-s%e1%ba%a3n-ph%e1%bb%a5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bc1f87bb951c7777ded1b18b9db08755?s=96&#38;d=identicon" medium="image">
			<media:title type="html">luongthanhbinh</media:title>
		</media:content>
	</item>
		<item>
		<title>Implementing the Singleton Pattern in C#</title>
		<link>http://luongthanhbinh.wordpress.com/2007/05/14/implementing-the-singleton-pattern-in-c/</link>
		<comments>http://luongthanhbinh.wordpress.com/2007/05/14/implementing-the-singleton-pattern-in-c/#comments</comments>
		<pubDate>Mon, 14 May 2007 16:13:28 +0000</pubDate>
		<dc:creator>luongthanhbinh</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[NHibernate]]></category>

		<guid isPermaLink="false">http://luongthanhbinh.wordpress.com/2007/05/14/implementing-the-singleton-pattern-in-c/</guid>
		<description><![CDATA[The singleton pattern is one of the best-known patterns in software engineering. Essentially, a singleton is a class which only allows a single instance of itself to be created, and usually gives simple access to that instance. Most commonly, singletons don&#8217;t allow any parameters to be specified when creating the instance &#8211; as otherwise a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=luongthanhbinh.wordpress.com&amp;blog=1084690&amp;post=13&amp;subd=luongthanhbinh&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>       The singleton pattern is one of the best-known patterns in software engineering.       Essentially, a singleton is a class which only allows a single instance of itself       to be created, and usually gives simple access to that instance. Most commonly,       singletons don&#8217;t allow any parameters to be specified when creating the instance &#8211;       as otherwise a second request for an instance but with a different parameter could       be problematic! (If the same instance should be accessed for all requests with the       same parameter, the factory pattern is more appropriate.) This article deals only with       the situation where no parameters are required. Typically a requirement of singletons       is that they are created lazily &#8211; i.e. that the instance isn&#8217;t created until it is       first needed.</p>
<p>There are various different ways of implementing the singleton pattern in C#. I shall       present them here in reverse order of elegance, starting with the most commonly seen,       which is not thread-safe, and working up to a fully lazily-loaded, thread-safe, simple       and highly performant version. Note that in the code here, I omit the <code>private</code>        modifier, as it is the default for class members. In many other languages such as Java, there       is a different default, and <code>private</code> should be used.</p>
<p>All these implementations share four common characteristics, however:</p>
<ul>
<li> 				A single constructor, which is private and parameterless.  				This prevents other classes from instantiating it (which would be a violation of the pattern). 				Note that it also prevents subclassing &#8211; if a singleton can be subclassed once, it can be 				subclassed twice, and if each of those subclasses can create an instance, the pattern is 				violated. The factory pattern can be used if you need a single instance of a base type, 				but the exact type isn&#8217;t known until runtime.</li>
<li>     		The class is sealed. This is unnecessary, strictly speaking, due to the above point,     		but may help the JIT to optimise things more.</li>
<li> 				A static variable which holds a reference to the single created instance, if any.</li>
<li> 				A public static means of getting the reference to the single created instance, creating 				one if necessary.</li>
</ul>
<p>Note that all of these implementations also use a public static property <code>Instance</code>       as the means of accessing the instance. In all cases, the property could easily be converted       to a method, with no impact on thread-safety or performance.</p>
<h2>First version &#8211; not thread-safe</h2>
<table class="code">
<tr>
<td>
<pre><span class="Attention">// Bad code! Do not use!</span>
<span class="Modifier">public</span> <span class="Modifier">sealed</span> <span class="ReferenceType">class</span> Singleton
{
    <span class="Modifier">static</span> Singleton instance=<span class="Keyword">null</span>;

    Singleton()
    {
    }

    <span class="Modifier">public</span> <span class="Modifier">static</span> Singleton Instance
    {
        get
        {
            <span class="Statement">if</span> (instance==<span class="Keyword">null</span>)
            {
                instance = <span class="Keyword">new</span> Singleton();
            }
            <span class="Statement">return</span> instance;
        }
    }
}</pre>
</td>
</tr>
</table>
<p>As hinted at before, the above is not thread-safe. Two different threads could both       have evaluated the test <code>if (instance==null)</code> and found it to be true,       then both create instances, which violates the singleton pattern. Note that in fact       the instance may already have been created before the expression is evaluated, but       the memory model doesn&#8217;t guarantee that the new value of instance will be seen by       other threads unless suitable memory barriers have been passed.</p>
<h2>Second version &#8211; simple thread-safety</h2>
<table class="code">
<tr>
<td>
<pre><span class="Modifier">public</span> <span class="Modifier">sealed</span> <span class="ReferenceType">class</span> Singleton
{
    <span class="Modifier">static</span> Singleton instance=<span class="Keyword">null</span>;
    <span class="Modifier">static</span> <span class="Modifier">readonly</span> <span class="ReferenceType">object</span> padlock = <span class="Keyword">new</span> <span class="ReferenceType">object</span>();

    Singleton()
    {
    }

    <span class="Modifier">public</span> <span class="Modifier">static</span> Singleton Instance
    {
        get
        {
            <span class="Statement">lock</span> (padlock)
            {
                <span class="Statement">if</span> (instance==<span class="Keyword">null</span>)
                {
                    instance = <span class="Keyword">new</span> Singleton();
                }
                <span class="Statement">return</span> instance;
            }
        }
    }
}</pre>
</td>
</tr>
</table>
<p>This implementation is thread-safe. The thread takes out a lock on a shared       object, and then checks whether or not the instance has been created before creating the instance.       This takes care of the memory barrier issue (as locking makes sure that       all reads occur logically after the lock acquire, and unlocking makes sure that all writes occur       logically before the lock release) and ensures that only one thread will create an instance        (as only one thread can be in that part of the code at a time &#8211; by the time the second thread        enters it,the first thread will have created the instance, so the expression will evaluate to false).       Unfortunately, performance suffers as a lock is acquired every time the instance is requested.</p>
<p>Note that instead of locking on <code>typeof(Singleton)</code> as some versions of this        implementation do, I lock on the value of a static variable which is private to the class.       Locking on objects which other classes can access and lock on (such as the type) risks       performance issues and even deadlocks. This is a general style preference of mine &#8211; wherever       possible, only lock on objects specifically created for the purpose of locking, or which       document that they are to be locked on for specific purposes (e.g. for waiting/pulsing a queue).       Usually such objects should be private to the class they are used in. This helps to make       writing thread-safe applications significantly easier.</p>
<h2>Third version &#8211; attempted thread-safety using double-check locking</h2>
<table class="code">
<tr>
<td>
<pre><span class="Attention">// Bad code! Do not use!</span>
<span class="Modifier">public</span> <span class="Modifier">sealed</span> <span class="ReferenceType">class</span> Singleton
{
    <span class="Modifier">static</span> Singleton instance=<span class="Keyword">null</span>;
    <span class="Modifier">static</span> <span class="Modifier">readonly</span> <span class="ReferenceType">object</span> padlock = <span class="Keyword">new</span> <span class="ReferenceType">object</span>();

    Singleton()
    {
    }

    <span class="Modifier">public</span> <span class="Modifier">static</span> Singleton Instance
    {
        get
        {
            <span class="Statement">if</span> (instance==<span class="Keyword">null</span>)
            {
                <span class="Statement">lock</span> (padlock)
                {
                    <span class="Statement">if</span> (instance==<span class="Keyword">null</span>)
                    {
                        instance = <span class="Keyword">new</span> Singleton();
                    }
                }
            }
            <span class="Statement">return</span> instance;
        }
    }
}</pre>
</td>
</tr>
</table>
<p>This implementation attempts to be thread-safe without the necessity of taking out a lock every time.        Unfortunately, there are four downsides to the pattern:</p>
<ul>
<li> 				It doesn&#8217;t work in Java. This may seem an odd thing to comment on, but it&#8217;s worth knowing 				if you ever need the singleton pattern in Java, and C# programmers may well also be Java 				programmers. The Java memory model doesn&#8217;t ensure that the constructor completes before 				the reference to the new object is assigned to instance. The Java memory model is going 				through a reworking for version 1.5, but double-check locking is anticipated to still 				be broken after this. <em>(Note to self: Java 1.5 has been out for a while &#8211; I need to check         what the memory model changes are&#8230;)</em></li>
<li>         Without any memory barriers, it&#8217;s broken in .NET too. Making the <code>instance</code> variable          volatile can make it work, as would explicit memory barrier calls, although in the latter case even experts         can&#8217;t agree exactly which barriers are required. I tend to try to avoid situations where         experts don&#8217;t agree what&#8217;s right and what&#8217;s wrong!</li>
<li> 				It&#8217;s easy to get wrong. The pattern needs to be pretty much exactly as above &#8211; any 				significant changes are likely to impact either performance or correctness.</li>
<li> 				It still doesn&#8217;t perform as well as the later implementations.</li>
</ul>
<h2>Fourth version &#8211; not quite as lazy, but thread-safe without using locks</h2>
<table class="code">
<tr>
<td>
<pre><span class="Modifier">public</span> <span class="Modifier">sealed</span> <span class="ReferenceType">class</span> Singleton
{
    <span class="Modifier">static</span> <span class="Modifier">readonly</span> Singleton instance=<span class="Keyword">new</span> Singleton();

    <span class="InlineComment">// Explicit static constructor to tell C# compiler</span>
    <span class="InlineComment">// not to mark type as beforefieldinit</span>
    <span class="Modifier">static</span> Singleton()
    {
    }

    Singleton()
    {
    }

    <span class="Modifier">public</span> <span class="Modifier">static</span> Singleton Instance
    {
        get
        {
            <span class="Statement">return</span> instance;
        }
    }
}</pre>
</td>
</tr>
</table>
<p>As you can see, this is really is extremely simple &#8211; but why is it thread-safe and how lazy is it?       Well, static constructors in C# are specified to execute only when an instance of the class is       created or a static member is referenced, and to execute only once per AppDomain. Given that       this check for the type being newly constructed needs to be executed whatever else happens, it       will be faster than adding extra checking as in the previous examples. There are a couple of        wrinkles, however:</p>
<ul>
<li>           It&#8217;s not as lazy as the other implementations. In particular, if you have static members           other than <code>GetInstance</code>, the first reference to those members will involve           creating the instance. This is corrected in the next implementation.</li>
<li>           There are complications if one static constructor invokes another which invokes the           first again. Look in the .NET specifications (currently section 9.5.3 of partition II)            for more details about the exact nature  of type initializers &#8211; they&#8217;re unlikely to bite you,            but it&#8217;s worth being aware of the consequences of static constructors which refer to each            other in a cycle.</li>
<li>           The laziness of type initializers is only guaranteed by .NET when the type isn&#8217;t           marked with a special flag called <code>beforefieldinit</code>. Unfortunately,           the C# compiler (as provided in the .NET 1.1 runtime, at least) marks all types           which don&#8217;t have a static constructor (i.e. a block which looks           like a constructor but is marked static) as <code>beforefieldinit</code>. I now           have a <a href="http://www.yoda.arachsys.com/csharp/beforefieldinit.html">discussion page</a> with more details about           this issue. Also note that it affects performance, as discussed near the bottom           of this article.</li>
</ul>
<p>One shortcut you can take with this implementation (and only this one) is to just make        <code>instance</code> a public static readonly variable, and get rid of the property entirely.       This makes the basic skeleton code absolutely tiny! Many people, however, prefer to have a       property in case further action is needed in future, and JIT inlining is likely to make       the performance identical. (Note that the static constructor itself is still required       if you require laziness.)</p>
<h2>Fifth version &#8211; fully lazy instantiation</h2>
<table class="code">
<tr>
<td>
<pre><span class="Modifier">public</span> <span class="Modifier">sealed</span> <span class="ReferenceType">class</span> Singleton
{
    Singleton()
    {
    }

    <span class="Modifier">public</span> <span class="Modifier">static</span> Singleton Instance
    {
        get
        {
            <span class="Statement">return</span> Nested.instance;
        }
    }

    <span class="ReferenceType">class</span> Nested
    {
        <span class="InlineComment">// Explicit static constructor to tell C# compiler</span>
        <span class="InlineComment">// not to mark type as beforefieldinit</span>
        <span class="Modifier">static</span> Nested()
        {
        }

        <span class="Modifier">internal</span> <span class="Modifier">static</span> <span class="Modifier">readonly</span> Singleton instance = <span class="Keyword">new</span> Singleton();
    }
}</pre>
</td>
</tr>
</table>
<p>Here, instantiation is triggered by the first reference to the static member of the nested       class, which only occurs in <code>GetInstance</code>. This means the implementation is fully       lazy, but has all the performance benefits of the previous ones. Note that although nested       classes have access to the enclosing class&#8217;s private members, the reverse is not true, hence       the need for <code>instance</code> to be internal here. That doesn&#8217;t raise any other problems,       though, as the class itself is private. The code is a bit more complicated in order to make       the instantiation lazy, however.</p>
<h2>Performance vs laziness</h2>
<p>In many cases, you won&#8217;t actually require full laziness &#8211; unless your class initialization      	does something particularly time-consuming, or has some side-effect elsewhere, it&#8217;s probably     	fine to leave out the explicit static constructor shown above. This can increase performance     	as it allows the JIT compiler to make a single check (for instance at the start of a method)     	to ensure that the type has been initialized, and then assume it from then on. If your     	singleton instance is referenced within a relatively tight loop, this can make a (relatively)       significant	performance difference. You should decide whether or not fully lazy instantiation        is required, and document this decision appropriately within the class. (See below for more on       performance, however.)</p>
<h2>Exceptions</h2>
<p>Sometimes, you need to do work in a singleton constructor which may throw an exception, but        might not be fatal to the whole application. Potentially, your application may be able to       fix the problem and want to try again. Using type initializers to construct the singleton       becomes problematic at this stage. Different runtimes handle this case differently,       but I don&#8217;t know of any which do the desired thing (running the type initializer again), and       even if one did, your code would be broken on other runtimes. To avoid these problems, I&#8217;d        suggest using the second pattern listed on the page &#8211; just use a simple lock, and go through        the check each time, building the instance in the method/property if it hasn&#8217;t already been       successfully built.</p>
<p>Thanks to Andriy Tereshchenko for raising this issue.</p>
<h2>A word on performance</h2>
<p>A lot of the reason for this page stemmed from people trying to be clever, and thus coming       up with the double-checked locking algorithm. There is an attitude of locking being expensive       which is common and misguided. I&#8217;ve written a very quick <a href="http://www.yoda.arachsys.com/csharp/SingletonBenchmark.cs">benchmark</a>       which just acquires singleton instances in a loop a billion ways, trying different variants.       It&#8217;s not terribly scientific, because in real life you may want to know how fast it is if each       iteration actually involved a call into a method fetching the singleton, etc. However, it does       show an important point. On my laptop, the slowest solution (by a factor of about 5) is the locking       one (solution 2). Is that important? Probably not, when you bear in mind that it still managed to       acquire the singleton a <em>billion</em> times in under 40 seconds. That means that if you&#8217;re &#8220;only&#8221;       acquiring the singleton four hundred thousand times per second, the cost of the acquisition       is going to be 1% of the performance &#8211; so improving it isn&#8217;t going to do a lot. Now, if you <em>are</em>       acquiring the singleton that often &#8211; isn&#8217;t it likely you&#8217;re using it within a loop? If you care       that much about improving the performance a little bit, why not declare a local variable outside the loop,       acquire the singleton once and <em>then</em> loop. Bingo, even the slowest implementation becomes easily       adequate.</p>
<p>I would be very interested to see a <em>real world</em> application where the difference between using       simple locking and using one of the faster solutions actually made a significant performance difference.</p>
<h2>Conclusion (modified slightly on January 7th 2006)</h2>
<p>There are various different ways of implementing the singleton pattern in C#.       A reader has written to me detailing a way he has encapsulated the synchronization aspect,       which while I acknowledge may be useful in a few <em>very</em> particular situations       (specifically where you want very high performance, <em>and</em> the ability to determine whether or not       the singleton has been created, <em>and</em> full laziness regardless of other static       members being called). I don&#8217;t personally see that situation coming up often enough       to merit going further with on this page, but please <a href="mailto:skeet@pobox.com">mail        me</a> if you&#8217;re in that situation.</p>
<p>My personal preference is for solution 4: the only time I would normally go away from it       is if I needed to be able to call other static methods without triggering initialization, or       if I needed to know whether or not the singleton has already been instantiated. I don&#8217;t remember       the last time I was in that situation, assuming I even have. In that case, I&#8217;d probably go       for solution 2, which is still nice and easy to get right.</p>
<p>Solution 5 is elegant, but trickier than 2 or 4, and as I said above, the benefits it provides       seem to only be rarely useful.</p>
<p>(I wouldn&#8217;t use solution 1 because it&#8217;s broken, and I wouldn&#8217;t use solution 3 because it has no        benefits over 5.)</p>
<p>http://www.yoda.arachsys.com/csharp/singleton.html</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/luongthanhbinh.wordpress.com/13/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/luongthanhbinh.wordpress.com/13/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/luongthanhbinh.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/luongthanhbinh.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/luongthanhbinh.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/luongthanhbinh.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/luongthanhbinh.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/luongthanhbinh.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/luongthanhbinh.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/luongthanhbinh.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/luongthanhbinh.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/luongthanhbinh.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/luongthanhbinh.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/luongthanhbinh.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/luongthanhbinh.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/luongthanhbinh.wordpress.com/13/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=luongthanhbinh.wordpress.com&amp;blog=1084690&amp;post=13&amp;subd=luongthanhbinh&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://luongthanhbinh.wordpress.com/2007/05/14/implementing-the-singleton-pattern-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bc1f87bb951c7777ded1b18b9db08755?s=96&#38;d=identicon" medium="image">
			<media:title type="html">luongthanhbinh</media:title>
		</media:content>
	</item>
		<item>
		<title>NHibernate (Real-World Architecture)</title>
		<link>http://luongthanhbinh.wordpress.com/2007/05/12/nhibernate-real-world-architecture/</link>
		<comments>http://luongthanhbinh.wordpress.com/2007/05/12/nhibernate-real-world-architecture/#comments</comments>
		<pubDate>Sat, 12 May 2007 15:50:03 +0000</pubDate>
		<dc:creator>luongthanhbinh</dc:creator>
				<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[Software Architechture]]></category>

		<guid isPermaLink="false">http://luongthanhbinh.wordpress.com/2007/05/12/nhibernate-real-world-architecture/</guid>
		<description><![CDATA[<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=luongthanhbinh.wordpress.com&amp;blog=1084690&amp;post=11&amp;subd=luongthanhbinh&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://luongthanhbinh.files.wordpress.com/2007/05/applicationarchitecture.gif" title="NHibernate (Real-World Architecture)"><img src="http://luongthanhbinh.files.wordpress.com/2007/05/applicationarchitecture.gif?w=544" alt="NHibernate (Real-World Architecture)" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/luongthanhbinh.wordpress.com/11/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/luongthanhbinh.wordpress.com/11/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/luongthanhbinh.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/luongthanhbinh.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/luongthanhbinh.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/luongthanhbinh.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/luongthanhbinh.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/luongthanhbinh.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/luongthanhbinh.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/luongthanhbinh.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/luongthanhbinh.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/luongthanhbinh.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/luongthanhbinh.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/luongthanhbinh.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/luongthanhbinh.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/luongthanhbinh.wordpress.com/11/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=luongthanhbinh.wordpress.com&amp;blog=1084690&amp;post=11&amp;subd=luongthanhbinh&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://luongthanhbinh.wordpress.com/2007/05/12/nhibernate-real-world-architecture/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bc1f87bb951c7777ded1b18b9db08755?s=96&#38;d=identicon" medium="image">
			<media:title type="html">luongthanhbinh</media:title>
		</media:content>

		<media:content url="http://luongthanhbinh.files.wordpress.com/2007/05/applicationarchitecture.gif" medium="image">
			<media:title type="html">NHibernate (Real-World Architecture)</media:title>
		</media:content>
	</item>
		<item>
		<title>Design-by-Contract: A Practical Introduction</title>
		<link>http://luongthanhbinh.wordpress.com/2007/05/10/design-by-contract-a-practical-introduction/</link>
		<comments>http://luongthanhbinh.wordpress.com/2007/05/10/design-by-contract-a-practical-introduction/#comments</comments>
		<pubDate>Thu, 10 May 2007 09:34:45 +0000</pubDate>
		<dc:creator>luongthanhbinh</dc:creator>
				<category><![CDATA[.net]]></category>

		<guid isPermaLink="false">http://luongthanhbinh.wordpress.com/2007/05/10/design-by-contract-a-practical-introduction/</guid>
		<description><![CDATA[There are two things I loathe during development: spending any time at all with the VS.NET debugger and seeing &#8220;object reference not set to an instance of an object&#8221; (which is usually why I&#8217;m in the debugger to begin with). The technique of Design-by-Contract (DBC) allows you to not only eschew these two issues but [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=luongthanhbinh.wordpress.com&amp;blog=1084690&amp;post=8&amp;subd=luongthanhbinh&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>There are two things I loathe during development:  spending any time at all with the VS.NET debugger and seeing &#8220;object reference not set to an instance of an object&#8221; (which is usually why I&#8217;m <em>in</em> the debugger to begin with).  The technique of Design-by-Contract (DBC) allows you to not only eschew these two issues but also assists with writing better self-documenting and more expressive code.  Design-by-Contract isn&#8217;t a new technique; in fact, the language Eiffel has DBC built right into it.  There&#8217;s a lot we can learn (and take) from Eiffel&#8217;s approach.</p>
<p><strong>Implicit Contracts</strong></p>
<p>Typically, if you&#8217;re not using DBC techniques, comments are (hopefully) included to describe to the client how the code should be used and any caveats to be expected.  (The &#8220;client&#8221; could be a third party calling your API, another developer on your own team, or, most often the case, another bit of code you&#8217;re writing yourself.)  As an example of an <em>implicit</em> contract &#8211; read &#8220;not DBC&#8221; &#8211; the following method fully describes the &#8220;contractual obligations&#8221; of the calling code:</p>
<p style="background:white none repeat scroll 0 50%;font-size:10pt;color:black;font-family:Courier New;">&nbsp;</p>
<p style="margin:0;"><span style="color:gray;">///</span><span style="color:green;"> </span><span style="color:gray;">&lt;summary&gt;</span><span style="color:green;">Gets the user for the given ID.</span><span style="color:gray;">&lt;/summary&gt;</span></p>
<p style="margin:0;"><span style="color:gray;">///</span><span style="color:green;"> </span><span style="color:gray;">&lt;param name=&#8221;id&#8221;&gt;</span><span style="color:green;">Should be &gt; 0</span><span style="color:gray;">&lt;/param&gt;</span></p>
<p style="margin:0;"><span style="color:blue;">public</span> <span style="color:teal;">User</span> GetUserWithIdOf(<span style="color:blue;">int</span> id,</p>
<p style="margin:0;">        <span style="color:teal;">UserRepository</span> userRepository) {</p>
<p style="margin:0;">    <span style="color:blue;">return</span> userRepository.GetById(id);</p>
<p style="margin:0;">}</p>
<p>The developer of this code has documented the restrictions for using the method &#8211; the &#8220;calling contract&#8221; &#8211; and, implicitly, has promised to return a User.  There are a few problems with this:</p>
<ul>
<li>If the client didn&#8217;t pay attention to the comments, there&#8217;s nothing to stop the client from passing in an invalid ID of 0.</li>
<li>The client could easily pass null for userRepository.  This would result in an &#8220;object reference&#8221; exception.</li>
<li>Since the returned User may be null, the client will have to check for this possibility or also risk an &#8220;object reference&#8221; exception.  In other words, the target method has not obligated itself to any sort of &#8220;response contract.&#8221;</li>
<li>What if, down the road, it becomes OK to pass 0 to the method.  If the developer neglects to update the comment, then the stated business rule will conflict with the inherit business rule within the code itself.</li>
</ul>
<p><strong>Explicit Contracts</strong></p>
<p>Design by Contract allows you to transform the <em>implicit </em>contract, described above, into an <em>explicit</em> bidirectional contract.  The bidirectional contract obligates both the client to invoke the method in a particular way and for the target method to guarantee a particular result.  If the contract is broken, then the breaking party will be severely chastised (conditionally&#8230;more on this soon).  The calling contract is expressed with one or more &#8220;pre-conditions&#8221; while the response contract is expressed with one or more &#8220;post-conditions.&#8221;  A pre-condition states &#8220;this is your end of the bargain which must be adhered to to call me.&#8221;  A post-condition states &#8220;this is my end of the bargain which you can count on me to enforce.&#8221;  What follows is a very explicit, and very inflexible, bidirectional contract:</p>
<p style="background:white none repeat scroll 0 50%;font-size:10pt;color:black;font-family:Courier New;">&nbsp;</p>
<p style="margin:0;"><span style="color:gray;">///</span><span style="color:green;"> </span><span style="color:gray;">&lt;summary&gt;</span><span style="color:green;">Gets the user for the given ID.</span><span style="color:gray;">&lt;/summary&gt;</span></p>
<p style="margin:0;"><span style="color:blue;">public</span> <span style="color:teal;">User</span> GetUserWithIdOf(<span style="color:blue;">int</span> id,</p>
<p style="margin:0;">        <span style="color:teal;">UserRepository</span> userRepository) {</p>
<p style="margin:0;">  <span style="color:green;">// Pre-conditions</span></p>
<p style="margin:0;">  <span style="color:blue;">if</span> (userRepository == <span style="color:blue;">null</span>)</p>
<p style="margin:0;">      <span style="color:blue;">throw</span> <span style="color:blue;">new</span> <span style="color:teal;">ArgumentNullException</span>(</p>
<p style="margin:0;">          <span style="color:maroon;">&#8220;userRepository&#8221;</span>);</p>
<p style="margin:0;">  <span style="color:blue;">if</span> (id &lt;= 0)</p>
<p style="margin:0;">      <span style="color:blue;">throw</span> <span style="color:blue;">new</span> <span style="color:teal;">ArgumentOutOfRangeException</span>(</p>
<p style="margin:0;">          <span style="color:maroon;">&#8220;id must be &gt; 0&#8243;</span>);</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">  <span style="color:teal;">User</span> foundUser = userRepository.GetById(id);</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">  <span style="color:green;">// Post-conditions</span></p>
<p style="margin:0;">  <span style="color:blue;">if</span> (foundUser == <span style="color:blue;">null</span>)</p>
<p style="margin:0;">      <span style="color:blue;">throw</span> <span style="color:blue;">new</span> <span style="color:teal;">KeyNotFoundException</span>(<span style="color:maroon;">&#8220;No user with &#8220;</span> +</p>
<p style="margin:0;">          <span style="color:maroon;">&#8220;an ID of &#8220;</span> + id.ToString() +</p>
<p style="margin:0;">          <span style="color:maroon;">&#8221; could be located.&#8221;</span>);</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">  <span style="color:blue;">return</span> foundUser;</p>
<p style="margin:0;">}</p>
<p>With the bidirectional contract now in place, almost all of the previous drawbacks have been addressed.  Furthermore, the code is much more self-documenting and requires very few comments to be explicit.  But a few drawbacks still exist:</p>
<ul>
<li>The contract is a bit verbose and easily blends in with the surrounding code.  Preferably, the contract should be more concise and easily spotted.</li>
<li>The contract above <em>always</em> throws exceptions.  It should be simpler to conditionally turn on exceptions for debug vs. release mode.  Furthermore, it should be simpler to always throw exceptions for pre-conditions, but only throw exceptions for post-conditions in debug mode.</li>
<li>What if we want to extend contracts to the class level, and not just on individual methods?  The above technique is difficult to extend for these purposes.</li>
<li>What if we want class level contracts to be extended (or restricted) within inherited classes?  Again, the above technique would become cumbersome &#8211; read &#8220;fragile and difficult to maintain&#8221; &#8211; when inheritance is involved.</li>
</ul>
<p><strong>Design-by-Contract Class Library</strong></p>
<p>Fortunately, a light-weight class library has been written for the .NET environment which addresses these issues:  <a href="http://www.codeproject.com/csharp/designbycontract.asp">http://www.codeproject.com/csharp/designbycontract.asp</a> [1].  With this library in place, the previous example could be expressed as follows:</p>
<p style="background:white none repeat scroll 0 50%;font-size:10pt;color:black;font-family:Courier New;">&nbsp;</p>
<p style="margin:0;"><span style="color:gray;">///</span><span style="color:green;"> </span><span style="color:gray;">&lt;summary&gt;</span><span style="color:green;">Gets the user for the given ID.</span><span style="color:gray;">&lt;/summary&gt;</span></p>
<p style="margin:0;"><span style="color:blue;">public</span> <span style="color:teal;">User</span> GetUserWithIdOf(<span style="color:blue;">int</span> id,</p>
<p style="margin:0;">      <span style="color:teal;">UserRepository</span> userRepository) {</p>
<p style="margin:0;">  <span style="color:teal;">Check</span>.Require(userRepository != <span style="color:blue;">null</span>,</p>
<p style="margin:0;">      <span style="color:maroon;">&#8220;userRepository may not be null&#8221;</span>);</p>
<p style="margin:0;">  <span style="color:teal;">Check</span>.Require(id &gt; 0, <span style="color:maroon;">&#8220;id must be &gt; 0&#8243;</span>);</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">  <span style="color:teal;">User</span> foundUser = userRepository.GetById(id);</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">  <span style="color:teal;">Check</span>.Ensure(foundUser != <span style="color:blue;">null</span>, <span style="color:maroon;">&#8220;No user with an &#8220;</span> +</p>
<p style="margin:0;">      <span style="color:maroon;">&#8220;ID of &#8220;</span> + id.ToString() + <span style="color:maroon;">&#8221; could be located.&#8221;</span>);</p>
<p style="margin:0;">  <span style="color:blue;">return</span> foundUser;</p>
<p style="margin:0;">}</p>
<p>Now, the contract is concise, explicit and easy to spot.  The library also provides for inheritance, allowing you to (only) weaken preconditions and (only) strengthen postconditions in overriding methods.  (As an exercise for the reader, you&#8217;ll also want to explore this library&#8217;s inclusion of an &#8220;invariant&#8221; which allows contracts to be applied to the class level.)  Finally, a few conditional compilation constants are provided to vary behavior between debug and release mode.  I recommend <em>not</em> varying the conditional compilation constants regardless of the compilation mode.  As commenters have noted, and as I have seen from using the library, behavior should not vary between debug in release mode.  A contract is always a contract.  Furthermore, variations in behavior may lead to difficult-to-reproduce bugs.  In my own, modified version of the DBC library, I have removed all capabilities of varying the contractual behavior based on compilation mode and, therefore, have all conditions turned on at all times.</p>
<p><strong>Day-to-Day Use &amp; Benefits</strong></p>
<p>From a practical standpoint, once you have the DBC class library in place, you&#8217;ll find the &#8220;Check.Require&#8221; to be, by far, the most useful addition to your coding arsenal.  In my projects, I find myself having one or two of these at the top of <em>every</em> method.  They only take a few seconds to write and save many hours in the debugger.  In fact I haven&#8217;t used, or needed, the debugger since adopting the principles of design-by-contract in earnest.  The benefits of Design-by-Contract [2] include:</p>
<ul>
<li>A better understanding of the method and how the software is constructed.</li>
<li>A systematic approach to building bug-free systems.</li>
<li>An effective framework for debugging, testing, and more generally, quality assurance.</li>
<li>A method for self-documenting software components.</li>
</ul>
<p>I hope this give a hint behind the benefits of design-by-contract&#8230;they&#8217;ll certainly become apparent the very first day you include the DBC class library in your own project.</p>
<p><strong>References and Additional Resources</strong></p>
<ul>
<li>[1] A simple class library for brining DBC to .NET:  <a href="http://www.codeproject.com/csharp/designbycontract.asp">http://www.codeproject.com/csharp/designbycontract.asp</a></li>
<li>[2] Eiffel&#8217;s Introduction to DBC:  <a href="http://archive.eiffel.com/doc/manuals/technology/contract/">http://archive.eiffel.com/doc/manuals/technology/contract/</a></li>
<li><a href="http://www.amazon.com/Design-Contract-Example-Richard-Mitchell/dp/0201634600">Design by Contract by Example</a> by Mitchell and McKim (Although I haven&#8217;t yet read this, it looks to be a strong overview of the subject.)</li>
</ul>
<p>Source from : http://devlicio.us/blogs/billy_mccafferty/archive/2006/09/22/Design_2D00_by_2D00_Contract_3A00_-A-Practical-Introduction.aspx</p>
<p>Code : http://www.codeproject.com/csharp/designbycontract.asp</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/luongthanhbinh.wordpress.com/8/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/luongthanhbinh.wordpress.com/8/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/luongthanhbinh.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/luongthanhbinh.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/luongthanhbinh.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/luongthanhbinh.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/luongthanhbinh.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/luongthanhbinh.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/luongthanhbinh.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/luongthanhbinh.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/luongthanhbinh.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/luongthanhbinh.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/luongthanhbinh.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/luongthanhbinh.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/luongthanhbinh.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/luongthanhbinh.wordpress.com/8/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=luongthanhbinh.wordpress.com&amp;blog=1084690&amp;post=8&amp;subd=luongthanhbinh&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://luongthanhbinh.wordpress.com/2007/05/10/design-by-contract-a-practical-introduction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bc1f87bb951c7777ded1b18b9db08755?s=96&#38;d=identicon" medium="image">
			<media:title type="html">luongthanhbinh</media:title>
		</media:content>
	</item>
	</channel>
</rss>
