<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Artur Trosin's blog </title><link>http://weblogs.asp.net/arturtrosin/default.aspx</link><description>No Pain, No Gain!</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Do your features fit together?</title><link>http://weblogs.asp.net/arturtrosin/archive/2011/05/05/do-you-features-fit-together.aspx</link><pubDate>Thu, 05 May 2011 07:05:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7777023</guid><dc:creator>Artur Trosin</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/arturtrosin/rsscomments.aspx?PostID=7777023</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/arturtrosin/commentapi.aspx?PostID=7777023</wfw:comment><comments>http://weblogs.asp.net/arturtrosin/archive/2011/05/05/do-you-features-fit-together.aspx#comments</comments><description>&lt;P mce_keep="true"&gt;Today a was listening to the &lt;A href="http://channel9.msdn.com/posts/Anders-Hejlsberg-Questions-and-Answers" mce_href="http://channel9.msdn.com/posts/Anders-Hejlsberg-Questions-and-Answers"&gt;great Q&amp;amp;A session with Anders Hejlsberg&lt;/A&gt;. But the post is not about the session itself, the thing that touched my ‘heart' &amp;nbsp;is that he mentioned a great point about the language design. There was a question to him about a missing feature in C#, and his answer was that a language is not (only) about features but it is more about "how all the features do they play together". &lt;/P&gt;
&lt;P&gt;I think it is very important point, and it applies not only language design but to design and architecture in general. While designing or architecting a project trying to add more ‘features' to the design (or architecture) we often forget &amp;nbsp;to think how do they play together. &amp;nbsp;And is very hard to analyze their impact from "play together" perspective. &lt;/P&gt;
&lt;P&gt;I think there someone will say that design (or architecture) is better when we can add features independently without affecting other packages, components, etc.. and I agree with that, but finally the software is about interaction on different levels (classes, packages, components,...) and the meaning is how these interaction play together when is added a new "feature" &amp;nbsp;and doesn't matter at which level of abstraction it is introduced.&lt;/P&gt;
&lt;P&gt;Yes, we can unit testing&amp;nbsp; for introducing a new feature, but it will solve the problem only partially answering the compile and covered business cases if they are broken or not, but it will not say anything about how ‘nicely do they play together ' all the features. &lt;/P&gt;
&lt;P&gt;Another technique is evaluative design (or architecture) where we can add small features and constantly refactoring to a better design every time we see a better way of doing. Last but not least technique that comes to mind is DDD techniques that make more transparent the entire design process in case of complex business solutions.&lt;/P&gt;
&lt;P&gt;I think you will be agree with &amp;nbsp;me that there is not general technique that can say to you about your design &amp;nbsp;"features play ability" but there are techniques that can make it better (doesn't matter these features are functional or non-factional). But it is important to take in consideration when we introduce a new feature how it will fit together with other existing features.&lt;/P&gt;
&lt;P&gt;(PS: Just thoughts, maybe &lt;A href="http://en.wikipedia.org/wiki/Interface_segregation_principle" mce_href="http://en.wikipedia.org/wiki/Interface_segregation_principle"&gt;Interface Segregation Principle&lt;/A&gt; applied ad various levels of abstraction can be used as a techniques in order to design a better "features play ability" ? )&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;Artur Trosin&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7777023" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/Design+Principles/default.aspx">Design Principles</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/Software+Architecture/default.aspx">Software Architecture</category></item><item><title>C# Domain-Driven Design Sample Released</title><link>http://weblogs.asp.net/arturtrosin/archive/2010/12/10/c-domain-driven-design-sample-released.aspx</link><pubDate>Fri, 10 Dec 2010 14:44:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7659258</guid><dc:creator>Artur Trosin</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/arturtrosin/rsscomments.aspx?PostID=7659258</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/arturtrosin/commentapi.aspx?PostID=7659258</wfw:comment><comments>http://weblogs.asp.net/arturtrosin/archive/2010/12/10/c-domain-driven-design-sample-released.aspx#comments</comments><description>&lt;P mce_keep="true"&gt;In the post I want to declare that NDDD Sample application(s) is released and share the work with you. You can access it here: &lt;A href="http://code.google.com/p/ndddsample" mce_href="http://code.google.com/p/ndddsample"&gt;http://code.google.com/p/ndddsample&lt;/A&gt;. NDDDSample from functionality perspective matches DDDSample 1.1.0 which is based Java and on joint effort by Eric Evans' company Domain Language and the Swedish software consulting company Citerus. But because NDDDSample is based on .NET technologies those two implementations could not be matched directly. However concepts, practices, values, patterns, especially DDD, are cross-language and cross-platform :). &lt;/P&gt;
&lt;P&gt;Implementation of .NET version of the application was an interesting journey because now as .NET developer I better understand the differences positive and negative between these two platforms. Even there are those differences they can be overtaken, in many cases it was not so hard to match a java libs\framework with .NET during the implementation. &lt;/P&gt;
&lt;P&gt;Here is a list of technology stack:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;1. .net 3.5 - framework&lt;/LI&gt;
&lt;LI&gt;2. VS.NET 2008 - IDE&lt;/LI&gt;
&lt;LI&gt;3. ASP.NET MVC2.0 - for administration and tracking UI&lt;/LI&gt;
&lt;LI&gt;4. WCF - communication mechanism&lt;/LI&gt;
&lt;LI&gt;5. NHibernate - ORM&lt;/LI&gt;
&lt;LI&gt;6. Rhino Commons - Nhibernate session management, base classes for in memory unit tests &lt;/LI&gt;
&lt;LI&gt;7. SqlLite - database &lt;/LI&gt;
&lt;LI&gt;8. Windsor - inversion of control container&lt;/LI&gt;
&lt;LI&gt;9. Windsor WCF facility - for better integration with NHibernate&lt;/LI&gt;
&lt;LI&gt;10. MvcContrib - and in particular its Castle WindsorControllerFactory in order to enable IoC for controllers&lt;/LI&gt;
&lt;LI&gt;11. WPF - for incident logging application&lt;/LI&gt;
&lt;LI&gt;12. Moq - mocking lib used for unit tests&lt;/LI&gt;
&lt;LI&gt;13. NUnit - unit testing framework&lt;/LI&gt;
&lt;LI&gt;14. Log4net - logging framework&lt;/LI&gt;
&lt;LI&gt;15. Cloud based on Azure SDK&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;These are not the latest technologies, tools and libs for the moment but if there are someone thinks that it would be useful to migrate the sample to latest current technologies and versions please comment.&lt;/P&gt;
&lt;P&gt;Cloud version of the application is based on Azure emulated environment provided by the SDK, so it hasn't been tested on ‘real' Azure scenario (we just do not have access to it).&lt;/P&gt;
&lt;P&gt;Thanks to participants, Eugen Gorgan who was involved directly in development, Ruslan Rusu and Victor Lungu spend their free time to discuss .NET specific decisions, Eugen Navitaniuc helped with Java related questions. Also, big thank to Cornel Cretu, he designed a nice logo and helped with some browser incompatibility issues.&lt;/P&gt;
&lt;P&gt;Any review and feedback are welcome!&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;Artur Trosin&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7659258" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/DDD/default.aspx">DDD</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/Patterns/default.aspx">Patterns</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/Software+Architecture/default.aspx">Software Architecture</category></item><item><title>Agile: Practical exercise </title><link>http://weblogs.asp.net/arturtrosin/archive/2009/12/29/agile-practical-exercise.aspx</link><pubDate>Tue, 29 Dec 2009 13:14:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7294086</guid><dc:creator>Artur Trosin</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/arturtrosin/rsscomments.aspx?PostID=7294086</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/arturtrosin/commentapi.aspx?PostID=7294086</wfw:comment><comments>http://weblogs.asp.net/arturtrosin/archive/2009/12/29/agile-practical-exercise.aspx#comments</comments><description>&lt;P mce_keep="true"&gt;Start is a point where our brain accepts something or reject, or at least puts on the skeptic shelf.&amp;nbsp; So, a good start is always important. Agile methodology usually falls in reject set with people with waterfall thinking or who never *really* tried it. Why?..., I'm going to discuss to in this article, also how we can fix it by doing a practical exercise for introducing practical side of Agile to new comers. &lt;/P&gt;
&lt;P&gt;I saw many times when people agree with agile statements, but some silent feelings are left that it will not work from practical perspective. As result the agile theory remains as a ‘famous' theory which is forgotten in time and space. Theory and Practice are percept in different ways, theory can be understood but it doesn't allow feeling the subject, and doesn't matter it is management Agile such as SCRUM or development Agile such as XP.&lt;/P&gt;
&lt;P&gt;&lt;I&gt;Randal L Schwartz quoted: The difference between theory and practice in theory is much less than the difference between theory and practice in practice.&lt;/I&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;In case of agile feeling emotional and practical part of the methodology is critical for its adaptation. In water fall methodologies the psychological part is less important because they are usually driven by bureaucracy, where any person can be replaced (even in waterfall is not true, it is just a try to reduce it), and so on...&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are many great resources with agile theory, even theory about practice; I don't want to list them here now. Here I want to make public already tested game which is a simple game that introduces people to Agile and SCRUM.&amp;nbsp; The game allows feeling practical side of agile to agile new comers and allow to understand agile as from inside and not from words of a person who did it.&amp;nbsp; It is important difference. The game is called ‘Air Plane Factory', the game consist in creating a line of production of paper airplanes in agile iterative manner. &lt;/P&gt;
&lt;P&gt;Here are more details &lt;A href="http://www.agileway.com.br/2009/11/16/the-airplane-factory-game/" mce_href="http://www.agileway.com.br/2009/11/16/the-airplane-factory-game/"&gt;http://www.agileway.com.br/2009/11/16/the-airplane-factory-game/&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;I've just tried to apply the game in our company with a group of ~12 persons divided in three teams. The result was only positive one: fun, great team work, communication, iterative PDCA (plan-do-check-act), visible improvement over iterations, transparency... and simple from process perspective. All these finalized with a great retrospective of agile benefits and values and applied during the game.&lt;/P&gt;
&lt;P&gt;Here is how it looks like:&lt;/P&gt;
&lt;P&gt;1. Iteration's Planing Meeting&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;IMG title="Agile " style="WIDTH: 640px; HEIGHT: 480px" height=480 alt="Agile " src="http://weblogs.asp.net/blogs/arturtrosin/AgilePractical/1.JPG" width=640 align=middle mce_src="http://weblogs.asp.net/blogs/arturtrosin/AgilePractical/1.JPG"&gt;&lt;/P&gt;
&lt;P&gt;2.&amp;nbsp;Iternation's implementation&amp;nbsp;phase&lt;/P&gt;
&lt;P&gt;&lt;IMG title="Air plain implementation" style="WIDTH: 640px; HEIGHT: 480px" height=480 alt="Air plain implementation" src="http://weblogs.asp.net/blogs/arturtrosin/AgilePractical/2.JPG" width=640 align=middle mce_src="http://weblogs.asp.net/blogs/arturtrosin/AgilePractical/2.JPG"&gt;&lt;/P&gt;
&lt;P&gt;3. Acceptance Testing at the end of the iteration&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;IMG title="Acceptance Testing" style="WIDTH: 640px; HEIGHT: 480px" height=480 alt="Acceptance Testing" src="http://weblogs.asp.net/blogs/arturtrosin/AgilePractical/3.JPG" width=640 align=middle mce_src="http://weblogs.asp.net/blogs/arturtrosin/AgilePractical/3.JPG"&gt;&lt;/P&gt;
&lt;P&gt;From my perspective, one advantage of the game over the real agile project is that the game shows on a smaller scale the entire agile process, making agile benefits and values more obvious. &lt;/P&gt;
&lt;P&gt;Thanks to game creators for sharing it to the community and team which accepted to participate.&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P mce_keep="true"&gt;Artur Trosin&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7294086" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/Agile/default.aspx">Agile</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/General+Software+Development/default.aspx">General Software Development</category></item><item><title>Domain-Driven Design: Two basic premises </title><link>http://weblogs.asp.net/arturtrosin/archive/2009/06/02/domain-driven-design-two-basic-premises.aspx</link><pubDate>Tue, 02 Jun 2009 07:53:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7105713</guid><dc:creator>Artur Trosin</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/arturtrosin/rsscomments.aspx?PostID=7105713</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/arturtrosin/commentapi.aspx?PostID=7105713</wfw:comment><comments>http://weblogs.asp.net/arturtrosin/archive/2009/06/02/domain-driven-design-two-basic-premises.aspx#comments</comments><description>&lt;P mce_keep="true"&gt;
&lt;P&gt;In the post I want to discuss about two basic Domain-Driven Design premises which stand on the base of all other DDD principles, patterns, and practices. DDD principles, patterns, and practices described by Eric Evans are not something invented by him, but are something that were discovered and used long experience path by many folks. So, all DDD goodies have just two simple premises which I will cover in the post. &lt;/P&gt;
&lt;H3&gt;Nowadays Complexity&lt;/H3&gt;
&lt;P&gt;
&lt;TABLE class=""&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class=""&gt;Before to dive in the premises lets discuss how they evolved. Nowadays more and more are automated various business domains (Domain - particular field of knowledge, e.g. Banking, Accounting, Assurance, E-Commerce, etc.. ) . The complex human work is automated as much as possible to reduce costs and earn velocity. All these are primary factors for successful business and top market place and the business competition. If to compare nowadays software situation with 90’ time span, when a lot of software solutions were common applications, now custom solutions are predominant, because: for a successful competition is necessary to be one step further. The tendency&amp;nbsp;is that&amp;nbsp;business complexity grows continuously dragging in software solution into “hell”. There are a lot of other things that can make software development complex but as we can see core of the complexity is business domain itself. &lt;/TD&gt;
&lt;TD class=""&gt;&lt;IMG title=complexity style="WIDTH: 150px; HEIGHT: 200px" height=200 alt=complexity src="http://weblogs.asp.net/blogs/arturtrosin/TwoPremises/Complexity.png" width=150 mce_src="http://weblogs.asp.net/blogs/arturtrosin/TwoPremises/Complexity.png"&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/P&gt;
&lt;TABLE class=""&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class=""&gt;
&lt;P&gt;In order to automate enterprise systems, complexity is the key factor that eventually can’t be omitted &lt;B&gt;ONLY CONTROLLED&lt;/B&gt;. Of course there are two types of complexity: &lt;/P&gt;
&lt;P&gt;1. &lt;A href="http://en.wikipedia.org/wiki/Essential_complexity" mce_href="http://en.wikipedia.org/wiki/Essential_complexity"&gt;essential&lt;/A&gt; – complexity that is reasonable and unavoidable that can’t(or shouldn’t) be omitted &lt;/P&gt;
&lt;P&gt;2. &lt;A href="http://en.wikipedia.org/wiki/Accidental_complexity" mce_href="http://en.wikipedia.org/wiki/Accidental_complexity"&gt;accidental&lt;/A&gt; - complexity which is non-essential to the problem to be solved &lt;/P&gt;
&lt;P&gt;So, by following the DDD premises we will be able better highlight and concentrate on the essential domain complexity. &lt;/P&gt;
&lt;TD class=""&gt;&lt;IMG title="Domain Knowledge" style="WIDTH: 150px; HEIGHT: 200px" height=200 alt="Domain Knowledge" src="http://weblogs.asp.net/blogs/arturtrosin/TwoPremises/DomaiKnowledge.png" width=150 mce_src="http://weblogs.asp.net/blogs/arturtrosin/TwoPremises/DomaiKnowledge.png"&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;
&lt;H3&gt;Two main DDD premises&lt;/H3&gt;
&lt;P&gt;Below are two premises that are also two DDD principles where all starts from. All other principle, patterns and practices are built on these principles OR they are compatible complementing each other. &lt;/P&gt;
&lt;P&gt;&lt;B&gt;1. Primary focus should be on the domain and domain logic &lt;/B&gt;&lt;/P&gt;
&lt;P&gt;&lt;B&gt;2. Complex domain designs should be based on a model &lt;/B&gt;&lt;/P&gt;
&lt;P&gt;First principle says that for most of the projects primary focus should be on business domain and domain logic. That is true for most of the projects but for a part of the project it isn’t. For example: &lt;/P&gt;
&lt;P&gt;1. For device that handle small logic but very fast such as routers, modems, etc… &lt;/P&gt;
&lt;P&gt;2. Frameworks or technical libraries where main focus is not a business domain &lt;/P&gt;
&lt;P&gt;Second principle says that design should be based on models. Model is very generic term, a model is a pattern, plan, representation (especially in miniature), or description designed to show the main object or workings of an object, system, or concept. &lt;/P&gt;
&lt;P&gt;Why models? Let’s see… &lt;/P&gt;
&lt;P&gt;Humans use models starting from beginning of its history, and use them in various scopes: &lt;/P&gt;
&lt;P&gt;1. Explain (very distinct from predict) &lt;BR&gt;2. Guide data collection &lt;BR&gt;3. Illuminate core dynamics &lt;BR&gt;4. Suggest dynamical analogies &lt;BR&gt;5. Discover new questions &lt;BR&gt;6. Promote a scientific habit of mind &lt;BR&gt;7. Bound (bracket) outcomes to plausible ranges &lt;BR&gt;8. Illuminate core uncertainties. &lt;BR&gt;9. Offer crisis options in near-real time &lt;BR&gt;10. Demonstrate tradeoffs / suggest efficiencies &lt;BR&gt;11. Challenge the robustness of prevailing theory through perturbations &lt;BR&gt;12. Expose prevailing wisdom as incompatible with available data &lt;BR&gt;13. Train practitioners &lt;BR&gt;14. Discipline the policy dialogue &lt;BR&gt;15. Educate the general public &lt;BR&gt;16. Reveal the apparently simple (complex) to be complex (simple) &lt;BR&gt;17. Etc… &lt;/P&gt;
&lt;P&gt;As an example I’ve got Atom Model. Which in translation means uncuttable, something that cannot be divided. On the right is modern model of the Atom which is evolution of the first model from the left. &lt;/P&gt;
&lt;P&gt;&lt;IMG title="Atom Models Evolution" style="WIDTH: 600px; HEIGHT: 300px" height=300 alt="Atom Models Evolution" src="http://weblogs.asp.net/blogs/arturtrosin/TwoPremises/AtomModels.PNG" width=600 align=middle mce_src="http://weblogs.asp.net/blogs/arturtrosin/TwoPremises/AtomModels.PNG"&gt; &lt;/P&gt;
&lt;P&gt;So, initial model from the left is initial “Atom” model,&amp;nbsp;where&amp;nbsp;the "Atom" term comes/starts from. That was a start for next models and theories. Scientists learn and discovered new models with new atom model structures through various experiments. The new model structures evolved to match new obtained results from the experiments, so model evolved through time and discussions. Even now, using the most powerful microscopes Atom structure can’t be revealed, that is why were a lot of models based on various theories and if a model and its theory doesn’t pass an experiment then the model and its theory is thrown. &lt;/P&gt;
&lt;P&gt;Models rarely represent something real or right. They could and are, more valuable when are not realistic. You could think that the best models are wrong. Yes, But they are fruitfully wrong! Models are just to highlight abstractions. &lt;/P&gt;
&lt;P&gt;&lt;B&gt;"Art is a lie that helps us see the truth." – Picasso &lt;BR&gt;"All models are wrong, but some are useful." - George Box&lt;/B&gt; &lt;/P&gt;
&lt;H3&gt;Even music has a Model!&lt;/H3&gt;
&lt;P&gt;Models can abstract very abstract things in order to materialize them for a better perception. From first sight Music is very abstract “concept” that is hard to imagine a model for it. &lt;/P&gt;
&lt;P&gt;&lt;IMG title="Music Model" style="WIDTH: 400px; HEIGHT: 200px" height=200 alt="Music Model" src="http://weblogs.asp.net/blogs/arturtrosin/TwoPremises/MusicModel.png" width=400 align=middle mce_src="http://weblogs.asp.net/blogs/arturtrosin/TwoPremises/MusicModel.png"&gt; &lt;/P&gt;
&lt;P&gt;This is a model of the music, the model allows to have a written form of music, to show some not obvious aspects that can’t be heard, to communicate. In music history were a lot of cases when symphonies were composed by completely deaf musicians. Again, above form is modern form to write music, the form was very different in incipient forms. &lt;/P&gt;
&lt;H3&gt;Best Model?&lt;/H3&gt;
&lt;P&gt;Can you answer for yourself which model is the best model? &lt;/P&gt;
&lt;P&gt;&lt;IMG title="Earth Models in Context" style="WIDTH: 500px; HEIGHT: 400px" height=400 alt="Earth Models in Context" src="http://weblogs.asp.net/blogs/arturtrosin/TwoPremises/EarthModels.PNG" width=500 align=middle mce_src="http://weblogs.asp.net/blogs/arturtrosin/TwoPremises/EarthModels.PNG"&gt; &lt;/P&gt;
&lt;P&gt;Of course, it depends. Depends on the context. If we need a political situation then first model is better if we need to explore internal earth structure then second model is better. Even both models represent earth, each model shows its abstractions, and has its context. Also you can notice that the model represent something real but model itself&amp;nbsp;is far to be real, even so it is&amp;nbsp;very valuable for&amp;nbsp;its specific purpose. &lt;/P&gt;
&lt;P&gt;As a conclusion for the theory, here is a definition of the model from DDD perspective: &lt;/P&gt;
&lt;P&gt;&lt;B&gt;Domain Model - is a rigorously organized and selective abstraction of the (Business) Domain knowledge.&lt;/B&gt; &lt;/P&gt;
&lt;H3&gt;Conclusion&lt;/H3&gt;
&lt;P&gt;The two DDD premises are very simple abbreviations for a set of practices that are used in various domains to handle complexity. Focus to domain logic based on models is very important to control complexity, as you can see not only in software development. &lt;/P&gt;
&lt;H3&gt;Refernces &amp;amp; Resources &lt;/H3&gt;
&lt;P&gt;&lt;B&gt;“Why Models”&lt;/B&gt; - &lt;A class="" href="http://jasss.soc.surrey.ac.uk/11/4/12.html" mce_href="http://jasss.soc.surrey.ac.uk/11/4/12.html"&gt;http://jasss.soc.surrey.ac.uk/11/4/12.html&lt;/A&gt;&lt;BR&gt;&lt;B&gt;“Domain-Driven Design: Tackling Complexity in the Heart of Software”&lt;/B&gt; - &lt;A class="" href="http://www.amazon.com/Domain-Driven-Design-Tackling-Complexity-Software/dp/0321125215" mce_href="http://www.amazon.com/Domain-Driven-Design-Tackling-Complexity-Software/dp/0321125215"&gt;http://www.amazon.com/Domain-Driven-Design-Tackling-Complexity-Software/dp/0321125215&lt;/A&gt;&lt;BR&gt;&lt;B&gt;For introduction to DDD and more resources DDD take a look to my post:&lt;/B&gt; &lt;A class="" href="http://weblogs.asp.net/arturtrosin/archive/2009/02/09/domain-driven-design-learning.aspx" mce_href="http://weblogs.asp.net/arturtrosin/archive/2009/02/09/domain-driven-design-learning.aspx"&gt;http://weblogs.asp.net/arturtrosin/archive/2009/02/09/domain-driven-design-learning.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Thank you, &lt;/P&gt;
&lt;P&gt;Artur Trosin &lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7105713" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/DDD/default.aspx">DDD</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/Design+Principles/default.aspx">Design Principles</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/General+Software+Development/default.aspx">General Software Development</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/Software+Architecture/default.aspx">Software Architecture</category></item><item><title>Software as Craft - Agile Conference in Chisinau </title><link>http://weblogs.asp.net/arturtrosin/archive/2009/05/20/software-as-craft-agile-conference-in-chisnau.aspx</link><pubDate>Wed, 20 May 2009 08:37:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7093394</guid><dc:creator>Artur Trosin</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/arturtrosin/rsscomments.aspx?PostID=7093394</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/arturtrosin/commentapi.aspx?PostID=7093394</wfw:comment><comments>http://weblogs.asp.net/arturtrosin/archive/2009/05/20/software-as-craft-agile-conference-in-chisnau.aspx#comments</comments><description>&lt;P mce_keep="true"&gt;
&lt;P&gt;In the post I want to highlight very important event for IT community that happened in the &lt;A href="http://en.wikipedia.org/wiki/Chişinău" mce_href="http://en.wikipedia.org/wiki/Chişinău"&gt;Chisinau&lt;/A&gt; capital of &lt;A href="http://en.wikipedia.org/wiki/Moldova" mce_href="http://en.wikipedia.org/wiki/Moldova"&gt;Moldova&lt;/A&gt;. Also I want to discuss my view on the &lt;A href="http://en.wikipedia.org/wiki/Chişinău" mce_href="http://en.wikipedia.org/wiki/Chişinău"&gt;Chisinau&lt;/A&gt;’s IT field from knowledge sharing perspective. &lt;/P&gt;
&lt;P&gt;Moldova is a small and relatively poor country in Europe but has a very well developed IT knowledge. Chisinau has at least three universities which graduates new IT specialists each year(&lt;A href="http://www.usm.md/math/" mce_href="http://www.usm.md/math/"&gt;USM&lt;/A&gt;, &lt;A href="http://www.utm.md/en/" mce_href="http://www.utm.md/en/"&gt;UTM&lt;/A&gt;, &lt;A href="http://www.ase.md/cartea/index.php?page=csie" mce_href="http://www.ase.md/cartea/index.php?page=csie"&gt;ASEM&lt;/A&gt;). That is why the country is very attractive for foreign IT investors. So as result most of the developers works for foreign investors as freelancer or in the local IT companies or migrate in better developed countries. &lt;/P&gt;
&lt;P&gt;So back to the event itself, as you can see that Moldova and especially Chisinau has a lot of developers BUT what is very specific for the developers within the Chisinau is that as I know it is not very common to get in groups, create communities such as: &lt;A href="http://en.wikipedia.org/wiki/Agile_software_development" mce_href="http://en.wikipedia.org/wiki/Agile_software_development"&gt;Agile&lt;/A&gt;, &lt;A href="http://en.wikipedia.org/wiki/Test-driven_development" mce_href="http://en.wikipedia.org/wiki/Test-driven_development"&gt;TDD&lt;/A&gt;, &lt;A href="http://en.wikipedia.org/wiki/Domain-driven_design" mce_href="http://en.wikipedia.org/wiki/Domain-driven_design"&gt;DDD&lt;/A&gt;, &lt;A href="http://altnetpedia.com/" mce_href="http://altnetpedia.com/"&gt;alt.net&lt;/A&gt;, etc… just for improving personal skills through knowledge sharing. The event is conference &lt;A href="http://www.softwareascraft.md/" mce_href="http://www.softwareascraft.md/"&gt;Software as Craft 2009, 14-16 May&lt;/A&gt;. I think the main intention of the conference was knowledge sharing and the second is to grow agile culture in Moldova, both are very important especially because both are far from to be on mature level in the most of the local IT companies. There weren’t any similar events before in Chisinau, so many thanks to &lt;A href="http://www.tacitknowledge.com/" mce_href="http://www.tacitknowledge.com/"&gt;Tacit Knowledge&lt;/A&gt; who is ONLY sponsor, organizer and initiator (I’m not Tacit Knowledge developer, I don’t advertise here my company). The conference was organized on the very high level. All that was absolutely free for any person who wished to attend. I appreciate that because not all companies can do that in crisis period, other part of the IT companies in Chisinau just want to extract all the juice from developers by outsourcing them without investing in their knowledge. &lt;/P&gt;
&lt;P&gt;As side effect of the conference, I hope, that developers’ community will be much closer to each other and open for knowledge sharing. For me was an interesting opportunity to discuss with bright folks and to capture important agile knowledge and practices from the persons such as &lt;A href="http://www.softwareascraft.md/content/speakers/tom_looy.html" mce_href="http://www.softwareascraft.md/content/speakers/tom_looy.html"&gt;Tom Looy&lt;/A&gt; who is &lt;A href="http://www.thoughtworks.com/" mce_href="http://www.thoughtworks.com/"&gt;ThoughWorks&lt;/A&gt; alumnus and at the moment Agile consultant. &lt;/P&gt;
&lt;P&gt;The conference covered interesting talks about Agile, TDD, DDD, Social Media, Parallel Programming..etc.. I think each person found its interests in each talk. &lt;/P&gt;
&lt;P&gt;As a conclusion of the post I want to say that nowadays is already old style of trying to learn something new sitting home alone and the only way to grow skills effectively is learning from each other by getting in communities. I don’t want to say that we should not work individually but I want to say that it is definitely not enough. Sadly but true is that among developers flows some skeptical ideas like “why I need to share my knowledge that so hard were accumulated by me”, so it is absolutely WRONG. Try to believe that all your output knowledge to community will have also a resonance back to you and finally you only will earn from that. Just take a look to &lt;A href="http://www.udidahan.com/" mce_href="http://www.udidahan.com/"&gt;Udi Dahan&lt;/A&gt;, &lt;A href="http://codebetter.com/blogs/gregyoung/default.aspx" mce_href="http://codebetter.com/blogs/gregyoung/default.aspx"&gt;Greg Young&lt;/A&gt;, &lt;A href="http://ayende.com/" mce_href="http://ayende.com/"&gt;Ayende Rahien&lt;/A&gt;, &lt;A href="http://www.martinfowler.com/" mce_href="http://www.martinfowler.com/"&gt;Martin Fowler&lt;/A&gt;, etc… they are very smart guys, try to understand why they share the knowledge with community using “tools” such as: Open Source Project, blogs, groups,… &lt;/P&gt;
&lt;P&gt;Thank you, &lt;/P&gt;
&lt;P&gt;Artur Trosin &lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7093394" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/Agile/default.aspx">Agile</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/Community+News/default.aspx">Community News</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/General+Software+Development/default.aspx">General Software Development</category></item><item><title>Apache Hash Code and Equals Builders</title><link>http://weblogs.asp.net/arturtrosin/archive/2009/05/08/apache-hash-code-and-equals-builders.aspx</link><pubDate>Fri, 08 May 2009 11:58:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7078155</guid><dc:creator>Artur Trosin</dc:creator><slash:comments>7</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/arturtrosin/rsscomments.aspx?PostID=7078155</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/arturtrosin/commentapi.aspx?PostID=7078155</wfw:comment><comments>http://weblogs.asp.net/arturtrosin/archive/2009/05/08/apache-hash-code-and-equals-builders.aspx#comments</comments><description>&lt;P&gt;In the post I want to present two useful utility classes that for a long time are used in Java world and developed within Apache Software Foundation. These are HashCodeBuilder and EqualsBuilder classes which were ported by me in C#. To implement a good method of Hash Code and Equals for any class is not an easy task, but the classes assists implementing &lt;STRONG&gt;object.GetHashCode&lt;/STRONG&gt; and &lt;STRONG&gt;object. Equals&lt;/STRONG&gt;. &lt;/P&gt;
&lt;P&gt;For equality comparation of objects should be used all relevant fields of the object, derived fields could be excluded. In order to build a Hash Code for an object is recommended to use same fields that were used for equality. &lt;/P&gt;
&lt;P&gt;I like to learn by examples, so let’s to start one. &lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;class&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;RgbColor&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;readonly&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;ushort&lt;/SPAN&gt; r;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;readonly&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;ushort&lt;/SPAN&gt; g;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;readonly&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;ushort&lt;/SPAN&gt; b;&lt;/P&gt;
&lt;P style="MARGIN: 0px" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; RgbColor(&lt;SPAN style="COLOR: blue"&gt;ushort&lt;/SPAN&gt; r, &lt;SPAN style="COLOR: blue"&gt;ushort&lt;/SPAN&gt; g, &lt;SPAN style="COLOR: blue"&gt;ushort&lt;/SPAN&gt; b)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.r = r;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.g = g;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.b = b;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;ushort&lt;/SPAN&gt; R&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt; { &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; r; }&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;ushort&lt;/SPAN&gt; B&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt; { &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; b; }&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;ushort&lt;/SPAN&gt; G&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt; { &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; g; }&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;That is an simple immutable &lt;A href="http://ayende.com/Blog/archive/2007/03/20/Plain-old-.Net-classes.aspx" mce_href="http://ayende.com/Blog/archive/2007/03/20/Plain-old-.Net-classes.aspx"&gt;POCO&lt;/A&gt; class that represents an RGB Color, and a typical implementation for the Equals and Hash Code are similar to: &lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;bool&lt;/SPAN&gt; Equals(&lt;SPAN style="COLOR: #2b91af"&gt;RgbColor&lt;/SPAN&gt; other)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; other.r == r &amp;amp;&amp;amp; other.g == g &amp;amp;&amp;amp; other.b == b;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;override&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt; GetHashCode()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt; result = r.GetHashCode();&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; result = (result * 397) ^ g.GetHashCode();&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; result = (result * 397) ^ b.GetHashCode();&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; result;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;[NOTE: irrelevant code blocks are omitted] &lt;/P&gt;
&lt;P&gt;TIP: these methods were generated using ReSharper. &lt;/P&gt;
&lt;P&gt;As we can see same logic is repeated especially same mathematical and logical operations every time, &lt;A href="http://en.wikipedia.org/wiki/Don't_repeat_yourself" mce_href="http://en.wikipedia.org/wiki/Don't_repeat_yourself"&gt;DRY&lt;/A&gt; principle will argue us and finally the embracement will not let us sleep. What to do? Get some drugs? &lt;/P&gt;Of course NO! Now we a lucky, we will apply HashCodeBuilder and and EqualsBuilder classes. &lt;BR&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;bool&lt;/SPAN&gt; Equals(&lt;SPAN style="COLOR: #2b91af"&gt;RgbColor&lt;/SPAN&gt; other)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;EqualsBuilder&lt;/SPAN&gt;()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; .Append(R, other.R)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; .Append(G, other.G)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; .Append(B, other.B)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; .IsEquals();&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;override&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt; GetHashCode()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;HashCodeBuilder&lt;/SPAN&gt;()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; .Append(R)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; .Append(G)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; .Append(B)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; .ToHashCode(); &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;With three primitive properties all is simple and nice but how to deal when we have collections, arrays, jagged arrays ect..? &lt;/P&gt;
&lt;P&gt;Flowing test demonstrate Append method generality: &lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;SPAN style="COLOR: #2b91af"&gt;Test&lt;/SPAN&gt;]&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; testRaggedArray()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;var&lt;/SPAN&gt; array1 = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;long&lt;/SPAN&gt;[2][];&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;var&lt;/SPAN&gt; array2 = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;long&lt;/SPAN&gt;[2][];&lt;/P&gt;
&lt;P style="MARGIN: 0px" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;for&lt;/SPAN&gt; (&lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt; i = 0; i &amp;lt; array1.Length; ++i)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; array1[i] = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;long&lt;/SPAN&gt;[2];&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; array2[i] = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;long&lt;/SPAN&gt;[2];&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;for&lt;/SPAN&gt; (&lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt; j = 0; j &amp;lt; array1[i].Length; ++j)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; array1[i][j] = (i + 1) * (j + 1);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; array2[i][j] = (i + 1) * (j + 1);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;Assert&lt;/SPAN&gt;.IsTrue(&lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;EqualsBuilder&lt;/SPAN&gt;().Append(array1, array1).IsEquals());&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;Assert&lt;/SPAN&gt;.IsTrue(&lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;EqualsBuilder&lt;/SPAN&gt;().Append(array1, array2).IsEquals());&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; array1[1][1] = 0;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;Assert&lt;/SPAN&gt;.IsTrue(!&lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;EqualsBuilder&lt;/SPAN&gt;().Append(array1, array2).IsEquals());&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;You can discover more usages by taking a look to the unit tests that are &lt;A href="http://code.google.com/p/ndddsample/source/browse/#svn/trunk/src/test/NDDDSample.Tests/Infrastructure/Builders" mce_href="http://code.google.com/p/ndddsample/source/browse/#svn/trunk/src/test/NDDDSample.Tests/Infrastructure/Builders"&gt;ported too&lt;/A&gt;. OR taking a look to java classes documentation because the usage is almost compatible. &lt;/P&gt;
&lt;P&gt;&lt;A href="http://commons.apache.org/lang/api/org/apache/commons/lang/builder/EqualsBuilder.html" mce_href="http://commons.apache.org/lang/api/org/apache/commons/lang/builder/EqualsBuilder.html"&gt;http://commons.apache.org/lang/api/org/apache/commons/lang/builder/EqualsBuilder.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;A href="http://commons.apache.org/lang/api/org/apache/commons/lang/builder/HashCodeBuilder.html" mce_href="http://commons.apache.org/lang/api/org/apache/commons/lang/builder/HashCodeBuilder.html"&gt;http://commons.apache.org/lang/api/org/apache/commons/lang/builder/HashCodeBuilder.html&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.java2s.com/Tutorial/Java/0500__Apache-Common/EqualsBuilder.htm" mce_href="http://www.java2s.com/Tutorial/Java/0500__Apache-Common/EqualsBuilder.htm"&gt;http://www.java2s.com/Tutorial/Java/0500__Apache-Common/EqualsBuilder.htm&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.java2s.com/Tutorial/Java/0500__Apache-Common/HashCodeBuilder.htm" mce_href="http://www.java2s.com/Tutorial/Java/0500__Apache-Common/HashCodeBuilder.htm"&gt;http://www.java2s.com/Tutorial/Java/0500__Apache-Common/HashCodeBuilder.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;I’m sure that could be other implementations, based on attributes for the class proprieties and common implementation for the hash code and equal in the base class using reflection. I’m talking about something similar to the &lt;A href="http://code.google.com/p/sharp-architecture/source/browse/trunk/src/SharpArch/SharpArch.Core/DomainModel/BaseObject.cs" mce_href="http://code.google.com/p/sharp-architecture/source/browse/trunk/src/SharpArch/SharpArch.Core/DomainModel/BaseObject.cs"&gt;Sharp Architecture&lt;/A&gt; approach. However even in the case could be used the Builder classes for various type handling flexibility. &lt;/P&gt;
&lt;P&gt;The classes are ported as part of Domain Driven Design Sample implemented in C#, so you can find within the trunk real usages of the classes. &lt;/P&gt;
&lt;P&gt;So source for the classes is here: &lt;/P&gt;
&lt;P&gt;&lt;A href="http://code.google.com/p/ndddsample/source/browse/trunk/src/app/infrastructure/NDDDSample.Infrastructure/Builders/EqualsBuilder.cs" mce_href="http://code.google.com/p/ndddsample/source/browse/trunk/src/app/infrastructure/NDDDSample.Infrastructure/Builders/EqualsBuilder.cs"&gt;EqualsBuilder.cs&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://code.google.com/p/ndddsample/source/browse/trunk/src/app/infrastructure/NDDDSample.Infrastructure/Builders/HashCodeBuilder.cs" mce_href="http://code.google.com/p/ndddsample/source/browse/trunk/src/app/infrastructure/NDDDSample.Infrastructure/Builders/HashCodeBuilder.cs"&gt;HashCodeBuilder.cs&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;About Domain Driven Design (DDD) Sample application I will blog more lately, for introduction in DDD in general please refer &lt;A href="http://weblogs.asp.net/arturtrosin/archive/2009/02/09/domain-driven-design-learning.aspx" mce_href="http://weblogs.asp.net/arturtrosin/archive/2009/02/09/domain-driven-design-learning.aspx"&gt;here&lt;/A&gt;. &lt;/P&gt;
&lt;P&gt;For folks who want to know more about Builder pattern and Fluent interfaces can refer to &lt;A href="http://weblogs.asp.net/arturtrosin/archive/2009/04/13/builder-pattern-through-fluent-interface.aspx" mce_href="http://weblogs.asp.net/arturtrosin/archive/2009/04/13/builder-pattern-through-fluent-interface.aspx"&gt;my previous post&lt;/A&gt;. &lt;/P&gt;
&lt;P&gt;Thank you for your attention, &lt;/P&gt;
&lt;P&gt;Artur Trosin &lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7078155" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/General+Software+Development/default.aspx">General Software Development</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/Open+Source/default.aspx">Open Source</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/Patterns/default.aspx">Patterns</category></item><item><title>Builder Pattern and Fluent Interface</title><link>http://weblogs.asp.net/arturtrosin/archive/2009/04/13/builder-pattern-through-fluent-interface.aspx</link><pubDate>Mon, 13 Apr 2009 11:53:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7045058</guid><dc:creator>Artur Trosin</dc:creator><slash:comments>9</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/arturtrosin/rsscomments.aspx?PostID=7045058</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/arturtrosin/commentapi.aspx?PostID=7045058</wfw:comment><comments>http://weblogs.asp.net/arturtrosin/archive/2009/04/13/builder-pattern-through-fluent-interface.aspx#comments</comments><description>&lt;P&gt;In the post I want to discuss the practical part of the Builder pattern and how builder pattern usage and implementation can be simplified by Fluent Interface, it will show how these two patterns can leave in harmony&amp;nbsp;with each other. &lt;/P&gt;
&lt;P&gt;For how many of us happened that requires enum types to be more complex types, to have a description for each enum or other additional fields. In the description field case we can attach attributes description above each enum value and using reflection to obtain them, in some cases it is a handy solution but in other it’s not. Of course each solution has its limitation, and in many cases enum types are not very helpful. &lt;/P&gt;
&lt;P&gt;As another solution, we can create a class with static readonly fields, this could be a typical implementation: &lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;class&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;EnumType&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;{&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &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;readonly&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;EnumType&lt;/SPAN&gt; ONE = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;EnumType&lt;/SPAN&gt;(1, &lt;SPAN style="COLOR: #a31515"&gt;"Descr1"&lt;/SPAN&gt;);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &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;readonly&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;EnumType&lt;/SPAN&gt; TWO = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;EnumType&lt;/SPAN&gt;(2, &lt;SPAN style="COLOR: #a31515"&gt;"Descr2"&lt;/SPAN&gt;);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &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;readonly&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;EnumType&lt;/SPAN&gt; THREE = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;EnumType&lt;/SPAN&gt;(3, &lt;SPAN style="COLOR: #a31515"&gt;"Descr3"&lt;/SPAN&gt;);&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;/P&gt;
&lt;P style="MARGIN: 0px" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;readonly&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt; id;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;readonly&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt; description;&lt;/P&gt;
&lt;P style="MARGIN: 0px" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; EnumType(&lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt; id, &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt; description)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.description = description;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.id = id;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt; Id&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt; { &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; id; }&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt; Description&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt; { &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; description; }&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;}&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;Here are only Id, and Description fields but of course can be more or less depending on the requirements. &lt;/P&gt;
&lt;P&gt;Of course, using class instead of enums we will lose other facilities one of them is switch structure usage. To solve last issue I will try to apply Builder pattern. Shortly Builder pattern is a design pattern and its focus is on constructing a complex object step by step. Maybe we will not use it in its “GoF form”, but finally the idea of the patterns is that they are not ready to use solution they are adaptable and should be adapted to the context. &lt;/P&gt;
&lt;P&gt;What it will “build” is the switch structure that we can use for class types, similar to above EnumTypes class, but of course our switch usage is not limited only to the type. &lt;/P&gt;
&lt;P&gt;Here is a test that will try to pass further: &lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;[&lt;SPAN style="COLOR: #2b91af"&gt;Test&lt;/SPAN&gt;]&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; CanCreateSimpleSwitchBuilder()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;{&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;EnumType&lt;/SPAN&gt; state = &lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;var&lt;/SPAN&gt; enumType = &lt;SPAN style="COLOR: #2b91af"&gt;EnumType&lt;/SPAN&gt;.THREE;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;var&lt;/SPAN&gt; builder = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;SimpleSwitchBuilder&lt;/SPAN&gt;();&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; builder.Switch(enumType);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; builder.Case(&lt;SPAN style="COLOR: #2b91af"&gt;EnumType&lt;/SPAN&gt;.ONE);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; builder.Body(() =&amp;gt; { &lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;.WriteLine(&lt;SPAN style="COLOR: #2b91af"&gt;EnumType&lt;/SPAN&gt;.ONE); state = &lt;SPAN style="COLOR: #2b91af"&gt;EnumType&lt;/SPAN&gt;.ONE; });&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; builder.Case(&lt;SPAN style="COLOR: #2b91af"&gt;EnumType&lt;/SPAN&gt;.TWO);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; builder.Case(&lt;SPAN style="COLOR: #2b91af"&gt;EnumType&lt;/SPAN&gt;.THREE);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; builder.Body(() =&amp;gt; { &lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;.WriteLine(&lt;SPAN style="COLOR: #a31515"&gt;"-&amp;gt;"&lt;/SPAN&gt; + &lt;SPAN style="COLOR: #2b91af"&gt;EnumType&lt;/SPAN&gt;.TWO + &lt;SPAN style="COLOR: #2b91af"&gt;EnumType&lt;/SPAN&gt;.THREE); state = &lt;SPAN style="COLOR: #2b91af"&gt;EnumType&lt;/SPAN&gt;.TWO; });&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; builder.Default.DefBody(() =&amp;gt; &lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;.WriteLine(&lt;SPAN style="COLOR: #a31515"&gt;"Def"&lt;/SPAN&gt;));&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; builder.Do();&lt;/P&gt;
&lt;P style="MARGIN: 0px" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;Assert&lt;/SPAN&gt;.AreEqual(state, &lt;SPAN style="COLOR: #2b91af"&gt;EnumType&lt;/SPAN&gt;.TWO);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;}&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;I will not show the SimpleSwitchBuilder code for the test which will pass it because usage of the SimpleSwitchBuilder class is ugly. But the idea is simple, Switch method sets state which will be tested against each Case value, then are Case methods which can cascade and a body represents a action that will be executed when Do method is invoked, if there is no Case for the Switch value then is executed Default action if it is specified. &lt;/P&gt;
&lt;P&gt;To increase readability we will introduce fluency for the SimpleSwitchBuilder: &lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;[&lt;SPAN style="COLOR: #2b91af"&gt;Test&lt;/SPAN&gt;]&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; CanCreateSimpleFluentSwitchBuilder()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;{&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;EnumType&lt;/SPAN&gt; state = &lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;EnumType&lt;/SPAN&gt; enumType = &lt;SPAN style="COLOR: #2b91af"&gt;EnumType&lt;/SPAN&gt;.THREE;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;SimpleSwitchBuilder&lt;/SPAN&gt;()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .Switch(enumType)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; .Case(&lt;SPAN style="COLOR: #2b91af"&gt;EnumType&lt;/SPAN&gt;.ONE)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; .Body(() =&amp;gt; { &lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;.WriteLine(&lt;SPAN style="COLOR: #2b91af"&gt;EnumType&lt;/SPAN&gt;.ONE); state = &lt;SPAN style="COLOR: #2b91af"&gt;EnumType&lt;/SPAN&gt;.ONE; })&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; .Case(&lt;SPAN style="COLOR: #2b91af"&gt;EnumType&lt;/SPAN&gt;.TWO)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; .Case(&lt;SPAN style="COLOR: #2b91af"&gt;EnumType&lt;/SPAN&gt;.THREE)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; .Body(() =&amp;gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;.WriteLine(&lt;SPAN style="COLOR: #a31515"&gt;"-&amp;gt;"&lt;/SPAN&gt; + &lt;SPAN style="COLOR: #2b91af"&gt;EnumType&lt;/SPAN&gt;.TWO + &lt;SPAN style="COLOR: #2b91af"&gt;EnumType&lt;/SPAN&gt;.THREE);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; state = &lt;SPAN style="COLOR: #2b91af"&gt;EnumType&lt;/SPAN&gt;.TWO;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; })&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; .Default&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; .DefBody(() =&amp;gt; &lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;.WriteLine(&lt;SPAN style="COLOR: #a31515"&gt;"Def"&lt;/SPAN&gt;))&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .Do();&lt;/P&gt;
&lt;P style="MARGIN: 0px" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;Assert&lt;/SPAN&gt;.AreEqual(state, &lt;SPAN style="COLOR: #2b91af"&gt;EnumType&lt;/SPAN&gt;.TWO);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;}&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;The readability is increased making the each method return&amp;nbsp;itself&amp;nbsp;(this), That is how we&amp;nbsp;introduce the fluency. &lt;/P&gt;
&lt;P&gt;Here is the code for the Simple Builder: &lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;class&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;SimpleSwitchBuilder&lt;/SPAN&gt; &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;{&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;Action&lt;/SPAN&gt; defaultAction;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; testObject;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;IList&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt;&amp;gt; caseList;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;readonly&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;IDictionary&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #2b91af"&gt;Action&lt;/SPAN&gt;&amp;gt; caseActions = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;Dictionary&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #2b91af"&gt;Action&lt;/SPAN&gt;&amp;gt;();&lt;/P&gt;
&lt;P style="MARGIN: 0px" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; SimpleSwitchBuilder() { }&lt;/P&gt;
&lt;P style="MARGIN: 0px" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;SimpleSwitchBuilder&lt;/SPAN&gt; Switch(&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; obj)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; caseList = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;List&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt;&amp;gt;();&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; testObject = obj;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;SimpleSwitchBuilder&lt;/SPAN&gt; Case(&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; obj)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; caseList.Add(obj);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;SimpleSwitchBuilder&lt;/SPAN&gt; Body(&lt;SPAN style="COLOR: #2b91af"&gt;Action&lt;/SPAN&gt; action)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;foreach&lt;/SPAN&gt; (&lt;SPAN style="COLOR: blue"&gt;var&lt;/SPAN&gt; switchCase &lt;SPAN style="COLOR: blue"&gt;in&lt;/SPAN&gt; caseList)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; caseActions.Add(switchCase, action);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; caseList = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;List&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt;&amp;gt;();&lt;/P&gt;
&lt;P style="MARGIN: 0px" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;SimpleSwitchBuilder&lt;/SPAN&gt; Default&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt; { &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;; }&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;SimpleSwitchBuilder&lt;/SPAN&gt; DefBody(&lt;SPAN style="COLOR: #2b91af"&gt;Action&lt;/SPAN&gt; action)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; defaultAction = action;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; Do()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;foreach&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #2b91af"&gt;KeyValuePair&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #2b91af"&gt;Action&lt;/SPAN&gt;&amp;gt; caseAction &lt;SPAN style="COLOR: blue"&gt;in&lt;/SPAN&gt; caseActions)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; (ReferenceEquals(caseAction.Key, testObject) || Equals(caseAction.Key, testObject))&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; caseAction.Value();&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt;;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; (defaultAction != &lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; defaultAction();&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;}&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;Ok, fluency is nice, but what if the switch class is not used correctly, and method invocation order is not correct? &lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;[&lt;SPAN style="COLOR: #2b91af"&gt;Test&lt;/SPAN&gt;]&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;[&lt;SPAN style="COLOR: #2b91af"&gt;ExpectedException&lt;/SPAN&gt;(&lt;SPAN style="COLOR: blue"&gt;typeof&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #2b91af"&gt;NullReferenceException&lt;/SPAN&gt;))]&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; CanCreateSimpleSwitchBuilderInWrongWay()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;{&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;SimpleSwitchBuilder&lt;/SPAN&gt;()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; .Default&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; .DefBody(() =&amp;gt; &lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;.WriteLine(&lt;SPAN style="COLOR: #a31515"&gt;"Def"&lt;/SPAN&gt;))&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; .Case(&lt;SPAN style="COLOR: #2b91af"&gt;EnumType&lt;/SPAN&gt;.ONE)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; .Body(() =&amp;gt; &lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;.WriteLine(&lt;SPAN style="COLOR: #2b91af"&gt;EnumType&lt;/SPAN&gt;.ONE))&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .Do();&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;}&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;The exception will rise, but it will not say anything about the problem, to solve the problem we can introduce validation of the methods call order BUT it could become very complex, the validation will be more complex than implementation itself, and the validation will hide the real switch logic. &lt;/P&gt;
&lt;P&gt;In order to solve the problem we will introduce interfaces, each interface will return its methods for the next switch step: &lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;interface&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;IDo&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; Do();&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;interface&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;IBody&lt;/SPAN&gt; : &lt;SPAN style="COLOR: #2b91af"&gt;IDo&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;ICase&lt;/SPAN&gt; Case(&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; obj);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;IDefault&lt;/SPAN&gt; Default { &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt;; }&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;interface&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;ICase&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;ICase&lt;/SPAN&gt; Case(&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; obj);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;IBody&lt;/SPAN&gt; Body(&lt;SPAN style="COLOR: #2b91af"&gt;Action&lt;/SPAN&gt; action);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;interface&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;IDefault&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;IDo&lt;/SPAN&gt; Body(&lt;SPAN style="COLOR: #2b91af"&gt;Action&lt;/SPAN&gt; action);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;interface&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;ISwitch&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;ICase&lt;/SPAN&gt; Switch(&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; obj);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;Implementing the interfaces will allow having following fluency without any complex validation and knowing details of usage of the methods, also the usage is more intuitive. &lt;/P&gt;
&lt;P&gt;Instead of many methods that can lead to wrong usage order (see pervious examples): &lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;IMG style="WIDTH: 462px; HEIGHT: 199px" height=199 src="http://weblogs.asp.net/blogs/arturtrosin/SwitchBuilder/WrongBuilder.PNG" width=462 border=1 mce_src="http://weblogs.asp.net/blogs/arturtrosin/SwitchBuilder/WrongBuilder.PNG"&gt;&lt;/P&gt;
&lt;P&gt;We will have nice and intuitive usage: &lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;IMG style="WIDTH: 434px; HEIGHT: 417px" height=417 src="http://weblogs.asp.net/blogs/arturtrosin/SwitchBuilder/RightBuilder.PNG" width=434 border=1 mce_src="http://weblogs.asp.net/blogs/arturtrosin/SwitchBuilder/RightBuilder.PNG"&gt;&lt;/P&gt;
&lt;P&gt;Here is the full &lt;A class="" title="Source Code" href="http://weblogs.asp.net/blogs/arturtrosin/SwitchBuilder/SwitchBuilder.zip" target=_blank mce_href="http://weblogs.asp.net/blogs/arturtrosin/SwitchBuilder/SwitchBuilder.zip"&gt;source code&lt;/A&gt;. &lt;/P&gt;
&lt;H3&gt;Conclusion&lt;/H3&gt;
&lt;P&gt;Builder pattern and fluent interface pattern in various scenarios can not only simplify and make more intuitive API usages but also simplify its validation logic. There are other ways of implementation of the fluent interface pattern, for example using nested class. &lt;/P&gt;
&lt;P&gt;Thank you, &lt;/P&gt;
&lt;P&gt;Artur Trosin &lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7045058" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/Code+Readability/default.aspx">Code Readability</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/Design+Principles/default.aspx">Design Principles</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/General+Software+Development/default.aspx">General Software Development</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/Patterns/default.aspx">Patterns</category></item><item><title>Rhino Tools: Rhino Security Guide</title><link>http://weblogs.asp.net/arturtrosin/archive/2009/04/02/rhino-tools-rhino-security-guide.aspx</link><pubDate>Thu, 02 Apr 2009 06:27:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7022354</guid><dc:creator>Artur Trosin</dc:creator><slash:comments>15</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/arturtrosin/rsscomments.aspx?PostID=7022354</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/arturtrosin/commentapi.aspx?PostID=7022354</wfw:comment><comments>http://weblogs.asp.net/arturtrosin/archive/2009/04/02/rhino-tools-rhino-security-guide.aspx#comments</comments><description>&lt;P http: ayende.com Blog category 548.aspx? mce_href="http://ayende.com/Blog/category/548.aspx" mce_keep="true&amp;#13;&amp;#10;   &lt;p&gt;&amp;#13;&amp;#10;  In the post I want to discuss basics of &amp;#13;&amp;#10;        &lt;a href="&gt;In the post I want to discuss basics of Rhino Security&lt;/A&gt; which was developed by &lt;A href="http://ayende.com/about-me.aspx" mce_href="http://ayende.com/about-me.aspx"&gt;Ayende&lt;/A&gt;. This is a nice security model implementation that could be easily integrated and adapted in many applications and scenarios. Intention of the post is to give good startup for Rhino Security. I will try to follow &lt;A href="http://en.wikipedia.org/wiki/KISS_principle" mce_href="http://en.wikipedia.org/wiki/KISS_principle"&gt;KISS&lt;/A&gt; (Keep It Simple) in my explanations, yes, I know that “&lt;A href="http://www.amazon.com/Its-All-Relative-Einsteins-Relativity/dp/0688519814" mce_href="http://www.amazon.com/Its-All-Relative-Einsteins-Relativity/dp/0688519814"&gt;It's All Relative&lt;/A&gt;” :) and also keep to minimum required infrastructure for the startup (mainly only required). Rhino Security is a part of &lt;A href="http://sourceforge.net/projects/rhino-tools/" mce_href="http://sourceforge.net/projects/rhino-tools/"&gt;Rhino tools&lt;/A&gt;, which is a set of already mature reusable classes and tools that cover various scenarios, such as well known:     &lt;/P&gt;
&lt;P&gt;1.&lt;A href="http://ayende.com/projects/rhino-mocks.aspx" mce_href="http://ayende.com/projects/rhino-mocks.aspx"&gt;Rhino Mocks&lt;/A&gt; - mocking framework &lt;/P&gt;
&lt;P&gt;2.&lt;A href="http://ayende.com/Blog/archive/2008/12/17/rhino-service-bus.aspx" mce_href="http://ayende.com/Blog/archive/2008/12/17/rhino-service-bus.aspx"&gt;Rhino Service bus&lt;/A&gt; – enterprise service bus implementation&lt;/P&gt;
&lt;P&gt;3.&lt;A href="http://ayende.com/Blog/category/486.aspx" mce_href="http://ayende.com/Blog/category/486.aspx"&gt;Rhino Common&lt;/A&gt; – set of reusable classes (working with threads, IoC, helpful Http Modules, ect..)&lt;/P&gt;
&lt;P&gt;4.&lt;A href="http://ayende.com/Blog/archive/2008/01/16/Rhino-ETL-2.0.aspx" mce_href="http://ayende.com/Blog/archive/2008/01/16/Rhino-ETL-2.0.aspx"&gt;Rhino ETL&lt;/A&gt; (&lt;A href="http://en.wikipedia.org/wiki/Extract,_transform,_load" mce_href="http://en.wikipedia.org/wiki/Extract,_transform,_load"&gt;Extract Transform Load&lt;/A&gt;) – library that allows moving data in various formats. &lt;/P&gt;
&lt;P&gt;5. &lt;A href="http://ayende.com/Blog/archive/2008/08/01/Rhino-Queues.aspx" mce_href="http://ayende.com/Blog/archive/2008/08/01/Rhino-Queues.aspx"&gt;Rhino Queues&lt;/A&gt; - queuing service that queues over the Internet&lt;/P&gt;
&lt;P&gt;6. &lt;A href="http://ayende.com/Blog/archive/2009/01/17/rhino.dht-ndash-persistent-amp-distributed-storage.aspx" mce_href="http://ayende.com/Blog/archive/2009/01/17/rhino.dht-ndash-persistent-amp-distributed-storage.aspx"&gt;Rhino DHT&lt;/A&gt; - Rhino Persistent Hash Table&lt;/P&gt;
&lt;P&gt;7.And many other goodies. &lt;/P&gt;
&lt;P&gt;Rhino Security in my opinion is less popular then other Rhino stuff, one reason could be that is on web is not so much information. That is why I want to put the basics of Rhino Security and show how easy you can setup working application based on Rhino Security(by “easy” I mean that is much easier to setup rhino security then to try to implement at least a little part of it). 
&lt;P&gt;Rhino Security implementation is not very huge in terms of code lines, but is based on many other set of classes. I will describe them shortly later. Rhino Security as a persistence mechanism uses &lt;A href="http://en.wikipedia.org/wiki/NHibernate" mce_href="http://en.wikipedia.org/wiki/NHibernate"&gt;NHibernate&lt;/A&gt; that allows you very easy to integrate with many &lt;A href="http://en.wikipedia.org/wiki/Relational_database_management_system" mce_href="http://en.wikipedia.org/wiki/Relational_database_management_system"&gt;RDBMS&lt;/A&gt; types. To more precise Rhino Security could be configured with both: &lt;A href="http://www.castleproject.org/ActiveRecord/" mce_href="http://www.castleproject.org/ActiveRecord/"&gt;Castle Active Record &lt;/A&gt;and NHibernate. Castle Active Record is&lt;A href="http://en.wikipedia.org/wiki/Active_record_pattern" mce_href="http://en.wikipedia.org/wiki/Active_record_pattern"&gt; Active Record pattern&lt;/A&gt; implementation which behind the scene uses NHibernate (mmm,… yes,…it is not only Active Record pattern implementation, it has much more other features than are described by classic Active Record pattern). I’ve chosen to use NHibernate because it is more popular then Castle Active Record (Castle AR) and other reason is that Castle AR can’t be used without NHibernate but NHibernate without Castle AR can :).&lt;/P&gt;
&lt;P&gt;Let’s do first steps and get all the Rhino bits from &lt;A href="http://subversion.tigris.org/" mce_href="http://subversion.tigris.org/"&gt;SVN&lt;/A&gt; repository, here is the SVN link:&lt;/P&gt;&lt;A href="https://rhino-tools.svn.sourceforge.net/svnroot/rhino-tools/trunk/" mce_href="https://rhino-tools.svn.sourceforge.net/svnroot/rhino-tools/trunk/"&gt;https://rhino-tools.svn.sourceforge.net/svnroot/rhino-tools/trunk/&lt;/A&gt; 
&lt;P&gt;in order to Check out the repository you can use any of SVN clients, there are many free:&lt;/P&gt;
&lt;P&gt;1)&lt;A href="http://tortoisesvn.net/about" mce_href="http://tortoisesvn.net/about"&gt;http://tortoisesvn.net/about&lt;/A&gt; - easy to use and is integrated in windows explorer &lt;/P&gt;
&lt;P&gt;2)&lt;A href="http://www.syntevo.com/smartsvn/download.html" mce_href="http://www.syntevo.com/smartsvn/download.html"&gt;SmartSVN&lt;/A&gt; – the SVN client has two versions, free and more limited and professional version, I like the client and I use it in day by day work, and even its free version is powerful enough to handle various scenarios. &lt;/P&gt;
&lt;P&gt;I will not dive deep in “&lt;A href="http://vegastrike.sourceforge.net/wiki/HowTo:Checkout_SVN" mce_href="http://vegastrike.sourceforge.net/wiki/HowTo:Checkout_SVN"&gt;How To checkout&lt;/A&gt;” details, so the result of checking out from the trunk is on the next image. On the image is the last trunk at the moment, &lt;B&gt;2077&lt;/B&gt;. Rhino Security is in “security” folder, but we will not touch it now. In the root folder are “readme” files for some additional information. Also in the root folder are various &lt;A href="http://nant.sourceforge.net/" mce_href="http://nant.sourceforge.net/"&gt;NAnt&lt;/A&gt; and bat files that will invoke NAnt and build entire projects tree. In order to build a little bit faster run “&lt;B&gt;build_without_tests.cmd&lt;/B&gt;” file. After a black screen and a lot of blinking lines will be generated “&lt;B&gt;build&lt;/B&gt;” folder that will contain all the generated assemblies for all Rhino projects and dependencies. &lt;/P&gt;
&lt;P&gt;If you have made all the steps successfully then let’s start and setup first Rhino Security project, if not then all required assemblies and project sample are i&lt;A class="" href="http://weblogs.asp.net/blogs/arturtrosin/RhinoSec/RhinoSecNhSetup.zip" mce_href="http://weblogs.asp.net/blogs/arturtrosin/RhinoSec/RhinoSecNhSetup.zip"&gt;n attached zip file&lt;/A&gt;. &lt;/P&gt;
&lt;P&gt;&lt;IMG title="Rhino Folder Structure" style="WIDTH: 226px; HEIGHT: 530px" height=530 alt="Rhino Folder Structure" src="http://weblogs.asp.net/blogs/arturtrosin/RhinoSec/RhinoFolderStruct.jpg" width=226 align=middle border=1 mce_src="http://weblogs.asp.net/blogs/arturtrosin/RhinoSec/RhinoFolderStruct.jpg"&gt; &lt;/P&gt;
&lt;P&gt;So, create a new folder where we will set our new project. Then in the root of just created folder create a new folder “&lt;B&gt;libs&lt;/B&gt;” where we will place all required assembly references and dependencies. &lt;/P&gt;
&lt;P&gt;Now, copy following 20 assemblies from Rhino’s generated “build” folder to “libs” folder:&amp;nbsp; 
&lt;P&gt;&lt;IMG title="Rhino Libs" style="WIDTH: 291px; HEIGHT: 461px" height=461 alt="Rhino Libs" src="http://weblogs.asp.net/blogs/arturtrosin/RhinoSec/RhinoLibs.jpg" width=291 align=middle border=1 mce_src="http://weblogs.asp.net/blogs/arturtrosin/RhinoSec/RhinoLibs.jpg"&gt; &lt;/P&gt;
&lt;P&gt;Then open visual studio and create a new console project, name the project “RhinoSecurity”, and place it in the created root folder (on the same level as “libs” folder). &lt;/P&gt;
&lt;P&gt;&lt;IMG title="Rhino Sample" alt="Rhino Sample" src="http://weblogs.asp.net/blogs/arturtrosin/RhinoSec/RhinoSample.jpg" align=middle border=1 mce_src="http://weblogs.asp.net/blogs/arturtrosin/RhinoSec/RhinoSample.jpg"&gt; &lt;/P&gt;
&lt;P&gt;In just created project reference following assemblies from our “libs” folder:&lt;/P&gt;
&lt;P&gt;&lt;IMG title="Rhino Sample" style="WIDTH: 254px; HEIGHT: 287px" height=287 alt="Rhino Sample" src="http://weblogs.asp.net/blogs/arturtrosin/RhinoSec/AssemblyStructure.jpg" width=254 align=middle border=1 mce_src="http://weblogs.asp.net/blogs/arturtrosin/RhinoSec/AssemblyStructure.jpg"&gt; &lt;/P&gt;
&lt;P&gt;NHibernate.ByteCode.Castle.dll – assembly is not used directly from our code, but we reference it because it is loaded runtime and should be copied to the output bin folder. The assembly contains implementation for three NHibernate interfaces which are used to generate in memory proxy classes for our &lt;A href="http://ayende.com/Blog/archive/2007/03/20/Plain-old-.Net-classes.aspx" mce_href="http://ayende.com/Blog/archive/2007/03/20/Plain-old-.Net-classes.aspx"&gt;POCO&lt;/A&gt; mapped classes such as User entity which will be discussed further (that is why we need to set mapped properties as virtual). In this case is used Castle but you can find other implementations.&lt;/P&gt;
&lt;P&gt;Now we have a good base to start type our logic. But, before to dive in implementation details, let’s discuss few Rhino Security types that can help us to integrate Rhino Security with our &lt;A href="http://en.wikipedia.org/wiki/Domain_model" mce_href="http://en.wikipedia.org/wiki/Domain_model"&gt;domain model&lt;/A&gt;. Most of the systems nowadays have User entity in the domain model, the User entity can have various proprieties that are specific for each different domains. Rhino Security allows attaching the security implementation to any User entity with minimal changes to the existent User entity, but how Rhino Security knows which entity from our model represents the User? For that is responsible &lt;B&gt;&lt;I&gt;Rhino.Security.IUser&lt;/I&gt;&lt;/B&gt; interface that marks the User entity, the only member of the interface which should be implemented is &lt;I&gt;&lt;B&gt;SecurityInfo&lt;/B&gt;&lt;/I&gt; member. &lt;/P&gt;
&lt;P&gt;Here is typical implementation of the interface which fits in many common user implementations: 
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;class&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;User&lt;/SPAN&gt; : &lt;SPAN style="COLOR: #2b91af"&gt;IUser&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;{&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;long&lt;/SPAN&gt; id;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt; name;&lt;/P&gt;
&lt;P style="MARGIN: 0px" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;virtual&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;long&lt;/SPAN&gt; Id&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt; { &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; id; }&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;set&lt;/SPAN&gt; { id = &lt;SPAN style="COLOR: blue"&gt;value&lt;/SPAN&gt;; }&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;virtual&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt; Name&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt; { &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; name; }&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;set&lt;/SPAN&gt; { name = &lt;SPAN style="COLOR: blue"&gt;value&lt;/SPAN&gt;; }&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; Gets or sets the security info for this user&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;value&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;The security info.&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;/value&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;virtual&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;SecurityInfo&lt;/SPAN&gt; SecurityInfo&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt; { &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;SecurityInfo&lt;/SPAN&gt;(name, id); }&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;}&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;The Id property is usually identity of the User entity (which not necessary should be a long). SecurityInfo property is used by Rhino Security to attach our user entity to Rhino Security implementation which is used internally by the framework to manage authorization logic for the User. &lt;I&gt;[Mapping file for the User entity and NHibernate configuration are in the provided &lt;A class="" href="http://weblogs.asp.net/blogs/arturtrosin/RhinoSec/RhinoSecNhSetup.zip" mce_href="http://weblogs.asp.net/blogs/arturtrosin/RhinoSec/RhinoSecNhSetup.zip"&gt;source code sample&lt;/A&gt;] &lt;/I&gt;Now I’ll try to describe main Rhino Security model entities from my point of view, which we will explore lately in practice: &lt;/P&gt;
&lt;P&gt;-&lt;B&gt;UserGroup&lt;/B&gt; – is a user group defined by its name, it’s used to associate users to the group and define common permissions for users that belong to the group. The groups can be structured hierarchically in parent/child relationship. In some cases you can think about users group in terms of Roles which have set of permissions ex: Administrator, Guest, etc… &lt;/P&gt;
&lt;P&gt;- &lt;B&gt;Operation&lt;/B&gt; – a named operation that also can be structured hierarchically using following convention: “&lt;B&gt;/Content/View&lt;/B&gt;”, “&lt;B&gt;/Content/Edit&lt;/B&gt;” etc… so if we create a new “&lt;B&gt;/Content/Edit&lt;/B&gt;” operation then are created two operations “&lt;B&gt;/Content&lt;/B&gt;” as parent and “&lt;B&gt;/Content/Edit&lt;/B&gt;” as child. Further you can allow or deny the operation for a &lt;B&gt;User&lt;/B&gt; or for a &lt;B&gt;UserGroup&lt;/B&gt;. When an operation is allowed or denied for a &lt;B&gt;User&lt;/B&gt;, &lt;B&gt;UserGroup&lt;/B&gt;, etc… also could be specified a level, levels defines importance of the permission, but very often is used Default Level which is equal to 1. &lt;B&gt;Permission&lt;/B&gt; with higher level is more dominant in taking decision of operation allowance. For example: if we deny operation “&lt;B&gt;/Content/View&lt;/B&gt;” with default level for a user and after that allow for the same operation but with level 9 then finally the operation will be allowed for the user. &lt;/P&gt;
&lt;P&gt;-&lt;B&gt;Permission&lt;/B&gt;- is result of allow or deny process for an operation (e.g. “&lt;B&gt;/Content/View&lt;/B&gt;”) for a &lt;B&gt;User&lt;/B&gt; or &lt;B&gt;UserGroup&lt;/B&gt; (or &lt;B&gt;EntityGroups&lt;/B&gt;). &lt;/P&gt;
&lt;P&gt;-&lt;B&gt;User&lt;/B&gt; – represent any entity that implements &lt;I&gt;&lt;B&gt;IUser&lt;/B&gt;&lt;/I&gt; interface, we already covered it above… &lt;/P&gt;
&lt;P&gt;I didn’t cover here &lt;B&gt;EntityGroups&lt;/B&gt;, &lt;B&gt;IEntityInformationExtractor&lt;/B&gt;, &lt;B&gt;Query Permissions&lt;/B&gt;,.. maybe I will cover them in the next posts because I want to concentrate on the basic and most common things, here I only want to mention that they exists and you can use them to associate permissions for any entity that implements &lt;B&gt;IEntityInformationExtractor&lt;/B&gt; interface. &lt;/P&gt;
&lt;P&gt;For a completeness of the entire image I want to show Rhino Security &lt;A href="http://en.wikipedia.org/wiki/Data_model" mce_href="http://en.wikipedia.org/wiki/Data_model"&gt;Data Model&lt;/A&gt; and to comment it: &lt;/P&gt;
&lt;P&gt;&lt;IMG title="Rhino Security Database Model" style="WIDTH: 624px; HEIGHT: 396px" height=396 alt="Rhino Security Database Model" src="http://weblogs.asp.net/blogs/arturtrosin/RhinoSec/RhinoSecurityModel.jpg" width=624 align=middle border=1 mce_src="http://weblogs.asp.net/blogs/arturtrosin/RhinoSec/RhinoSecurityModel.jpg"&gt; &lt;/P&gt;
&lt;P&gt;All tables which are prefixed with “&lt;I&gt;&lt;B&gt;security_&lt;/B&gt;&lt;/I&gt;” are related to directly Rhino Security, Users table is used to persist User entity. &lt;/P&gt;
&lt;P&gt;Again, tables from red region I won’t touch now because they are related to Entities, shortly, the tables from red region are used to associate permission for entities like Accounts from a given EntitiesGroups or to entities directly (omitting EntitiesGroups) that implements IEntityInformationExtractor which are related by &lt;B&gt;SecurityKey&lt;/B&gt; (Accounts.SecurityKey with security_EntityReferences.EntitySecurityKey). &lt;/P&gt;
&lt;P&gt;So, from the above diagram we can see that we can allow or deny operations by permission for Users or UserGroups. A User can belong to one or more UserGroups. Operations and UserGroups can be structured hierarchically in parent\child relationship. That’s it... Nothing complicated, is it?&lt;/P&gt;
&lt;P&gt;Back to Code: &lt;/P&gt;
&lt;P&gt;So, let’s initialize Rhino Security on order to make it work. &lt;/P&gt;
&lt;P&gt;First of all we need to initialize Windsor&lt;A href="http://en.wikipedia.org/wiki/Inversion_of_Control" mce_href="http://en.wikipedia.org/wiki/Inversion_of_Control"&gt; Inversion of Control&lt;/A&gt; Container and add at least two &lt;A href="http://www.castleproject.org/container/documentation/v1rc3/concepts/facility.html" mce_href="http://www.castleproject.org/container/documentation/v1rc3/concepts/facility.html"&gt;Windsor facilities&lt;/A&gt;: &lt;/P&gt;1) NHibernateUnitOfWorkFacility 
&lt;P&gt;2) RhinoSecurityFacility &lt;/P&gt;we can do it programmatically or using configuration file, here is programmatic version: 
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: green"&gt;//Create container&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;container = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;WindsorContainer&lt;/SPAN&gt;();&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: green"&gt;//Register Unit Of Work Facility instance&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;container.Kernel.AddFacility(&lt;SPAN style="COLOR: #a31515"&gt;"nh"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;NHibernateUnitOfWorkFacility&lt;/SPAN&gt;());&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: green"&gt;//Regiser Rhino Security Facility instance: &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: green"&gt;//1) provide Rhino’s DB table naming convetion: &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: green"&gt;//&amp;nbsp; Prefix '_'&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ex: security_Permissions or &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: green"&gt;//&amp;nbsp; Schema '.'(is default). ex: security.Permissions&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: green"&gt;//2) provide User Type that implements IUser&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;container.Kernel.AddFacility(&lt;SPAN style="COLOR: #a31515"&gt;"security"&lt;/SPAN&gt;,&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;RhinoSecurityFacility&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #2b91af"&gt;SecurityTableStructure&lt;/SPAN&gt;.Prefix, &lt;SPAN style="COLOR: blue"&gt;typeof&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #2b91af"&gt;User&lt;/SPAN&gt;)));&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;All code explanations are in the comments, only what I want to add is that we need to run the code once in application startup. &lt;/P&gt;
&lt;P&gt;The configurations could be setup in few ways, and most of them which I saw were using &lt;A href="http://ayende.com/Blog/archive/2007/10/25/Binsor-2.0.aspx" mce_href="http://ayende.com/Blog/archive/2007/10/25/Binsor-2.0.aspx"&gt;Rhino Bindsor&lt;/A&gt; which is &lt;A href="http://en.wikipedia.org/wiki/Domain-specific_programming_language" mce_href="http://en.wikipedia.org/wiki/Domain-specific_programming_language"&gt;Domain Specific Language&lt;/A&gt; written in &lt;A href="http://nathan.whiteboard-it.com/archive/2008/06/24/settings-dsl.aspx" mce_href="http://nathan.whiteboard-it.com/archive/2008/06/24/settings-dsl.aspx"&gt;Boo&lt;/A&gt; that allows configuring Castle Windsor Inversion of Control container without using any xml tag. Maybe some of you already noted I didn’t go with Boo way, because it can look as more “exotic” way for some folks. &lt;/P&gt;
&lt;P&gt;Next, we need to resolve Rhino Security repository\services\facades that will allow us to manage and query Rhino Security model: &lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: green"&gt;//The repository is main "player" that allows to manage security model&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;authorizationRepository = &lt;SPAN style="COLOR: #2b91af"&gt;IoC&lt;/SPAN&gt;.Resolve&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;IAuthorizationRepository&lt;/SPAN&gt;&amp;gt;();&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: green"&gt;//The service provides authorization information&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;authorizationService = &lt;SPAN style="COLOR: #2b91af"&gt;IoC&lt;/SPAN&gt;.Resolve&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;IAuthorizationService&lt;/SPAN&gt;&amp;gt;();&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: green"&gt;//Provide a fluent interface that can be used to assign permissions&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;permissionsBuilderService = &lt;SPAN style="COLOR: #2b91af"&gt;IoC&lt;/SPAN&gt;.Resolve&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;IPermissionsBuilderService&lt;/SPAN&gt;&amp;gt;();&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: green"&gt;//Allow to retrieve and remove permissions&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: green"&gt;//on users, user groups, entities groups and entities.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;permissionService = &lt;SPAN style="COLOR: #2b91af"&gt;IoC&lt;/SPAN&gt;.Resolve&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;IPermissionsService&lt;/SPAN&gt;&amp;gt;();&amp;nbsp; &lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;Now, let’s create a transient User entity and save it to DB. &lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: green"&gt;//Create a User&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;var&lt;/SPAN&gt; userArt = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;User&lt;/SPAN&gt; { Name = (&lt;SPAN style="COLOR: #a31515"&gt;"ArturTrosin"&lt;/SPAN&gt;) };&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;UnitOfWork&lt;/SPAN&gt;.CurrentSession.Save(userArt);&lt;/P&gt;&lt;/DIV&gt;&lt;!--EndFragment--&gt;
&lt;P&gt;The user entity we will use to operate with. Then create two groups, child and parent: &lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: green"&gt;//Create "AdminUserGroup" UsersGroup&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;authorizationRepository.CreateUsersGroup(&lt;SPAN style="COLOR: #a31515"&gt;"AdminUserGroup"&lt;/SPAN&gt;);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: green"&gt;//Create Child group for "AdminUserGroup"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;authorizationRepository.CreateChildUserGroupOf(&lt;SPAN style="COLOR: #a31515"&gt;"AdminUserGroup"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"GuestUserGroup"&lt;/SPAN&gt;);&lt;/P&gt;&lt;/DIV&gt;&lt;!--EndFragment--&gt;
&lt;P&gt;Then create three operations: &lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: green"&gt;//Create two operations: root /Content&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; operation &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: green"&gt;//&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; and its child /Content/Manage&amp;nbsp;&amp;nbsp; operation&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;authorizationRepository.CreateOperation(&lt;SPAN style="COLOR: #a31515"&gt;"/Content/Manage"&lt;/SPAN&gt;);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;UnitOfWork&lt;/SPAN&gt;.Current.TransactionalFlush();&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: green"&gt;//Create third operation as child of the /Content&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;authorizationRepository.CreateOperation(&lt;SPAN style="COLOR: #a31515"&gt;"/Content/View"&lt;/SPAN&gt;);&lt;/P&gt;&lt;/DIV&gt;&lt;!--EndFragment--&gt;
&lt;P&gt;Associate user with created group:&lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: green"&gt;//add user to "AdminUserGroup", so all further permissions for "AdminUserGroup"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: green"&gt;//group are aslo applied for the user also&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;authorizationRepository.AssociateUserWith(userArt, &lt;SPAN style="COLOR: #a31515"&gt;"AdminUserGroup"&lt;/SPAN&gt;); &lt;/P&gt;&lt;/DIV&gt;&lt;!--EndFragment--&gt;
&lt;P&gt;Here is how we can associate two permissions for a user group or a user: &lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: green"&gt;//Create Permission using Builder Pattern &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: green"&gt;//and its fluent interface:&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;permissionsBuilderService&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;//Allow "/Content" Operation &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; .Allow(&lt;SPAN style="COLOR: #a31515"&gt;"/Content"&lt;/SPAN&gt;)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;//for "AdminUserGroup"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; .For(&lt;SPAN style="COLOR: #a31515"&gt;"AdminUserGroup"&lt;/SPAN&gt;)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;//Could be specified On an entityGroup &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;//or an entity that implemented IEntityInformationExtractor&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; .OnEverything() &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;//Here could be specified Permission priority Level&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;//DefaultLevel is equal with 1&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; .DefaultLevel()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; .Save();&lt;/P&gt;
&lt;P style="MARGIN: 0px" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: green"&gt;//Create Deny permission for user with level 5&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;permissionsBuilderService&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; .Deny(&lt;SPAN style="COLOR: #a31515"&gt;"/Content/View"&lt;/SPAN&gt;)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; .For(userArt)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; .OnEverything()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; .Level(5)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; .Save();&lt;/P&gt;
&lt;P style="MARGIN: 0px" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;!--EndFragment--&gt;In the next code lines are demonstrated few Rhino Security methods that allows you to retrieve various info:&lt;BR&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: green"&gt;//Ask users allowance for an Operation&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;bool&lt;/SPAN&gt; isAllowedContentOp = authorizationService.IsAllowed(userArt, &lt;SPAN style="COLOR: #a31515"&gt;"/Content"&lt;/SPAN&gt;);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;bool&lt;/SPAN&gt; isAllowedContentManageOp = authorizationService.IsAllowed(userArt, &lt;SPAN style="COLOR: #a31515"&gt;"/Content/Manage"&lt;/SPAN&gt;);&lt;/P&gt;
&lt;P style="MARGIN: 0px" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: green"&gt;//Retrieve Rhino Security entities&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;UsersGroup&lt;/SPAN&gt; adminUsersGroupWithoutUser = authorizationRepository.GetUsersGroupByName(&lt;SPAN style="COLOR: #a31515"&gt;"AdminUserGroup"&lt;/SPAN&gt;);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Operation&lt;/SPAN&gt; contentViewOp = authorizationRepository.GetOperationByName(&lt;SPAN style="COLOR: #a31515"&gt;"/Content/View"&lt;/SPAN&gt;);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Permission&lt;/SPAN&gt;[] userArtPermission = permissionService.GetPermissionsFor(userArt);&lt;/P&gt;
&lt;P style="MARGIN: 0px" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: green"&gt;//Retrieve athorization info that can help to &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: green"&gt;//understand reason of allowance (or not) of an operation&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: green"&gt;//its very helpful for debuging&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;AuthorizationInformation&lt;/SPAN&gt; authInfo = authorizationService&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; .GetAuthorizationInformation(userArt, &lt;SPAN style="COLOR: #a31515"&gt;"/Content"&lt;/SPAN&gt;);&lt;/P&gt;&lt;/DIV&gt;And finally remove created entities: 
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: green"&gt;//Cleanup created entities&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;authorizationRepository.RemoveOperation(&lt;SPAN style="COLOR: #a31515"&gt;"/Content/Manage"&lt;/SPAN&gt;);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;authorizationRepository.RemoveOperation(&lt;SPAN style="COLOR: #a31515"&gt;"/Content/View"&lt;/SPAN&gt;);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;authorizationRepository.RemoveOperation(&lt;SPAN style="COLOR: #a31515"&gt;"/Content"&lt;/SPAN&gt;);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: green"&gt;//Remove child group first&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;authorizationRepository.RemoveUsersGroup(&lt;SPAN style="COLOR: #a31515"&gt;"GuestUserGroup"&lt;/SPAN&gt;);&amp;nbsp; &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;authorizationRepository.RemoveUsersGroup(&lt;SPAN style="COLOR: #a31515"&gt;"AdminUserGroup"&lt;/SPAN&gt;);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;
&lt;P style="MARGIN: 0px" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;authorizationRepository.RemoveUser(userArt);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;UnitOfWork&lt;/SPAN&gt;.CurrentSession.Delete(userArt);&amp;nbsp; &lt;/P&gt;&lt;/DIV&gt;&lt;!--EndFragment--&gt;
&lt;P&gt;&lt;A class="" href="http://weblogs.asp.net/blogs/arturtrosin/RhinoSec/RhinoSecNhSetup2.zip" mce_href="http://weblogs.asp.net/blogs/arturtrosin/RhinoSec/RhinoSecNhSetup.zip"&gt;Link to full source code and libs is here.&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Note that I didn’t show code of &lt;A href="http://martinfowler.com/eaaCatalog/unitOfWork.html" mce_href="http://martinfowler.com/eaaCatalog/unitOfWork.html"&gt;UoW&lt;/A&gt; Flush method calls, which persists changes to DB. And of course in order to run the code you need a database with Rhino Security DB schema in it similar to provided earlier, so there is a method which will do all the dirty work for you: &lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'"&gt;new&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'"&gt; &lt;SPAN style="COLOR: #2b91af"&gt;DbSchema&lt;/SPAN&gt;().Generate(container);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;The only thing that you should care is to create an empty DB (named &lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'"&gt;Security_Test&lt;/SPAN&gt;) and verify if connection string from &lt;B&gt;&lt;I&gt;hibernate.cfg.xml&lt;/I&gt;&lt;/B&gt; file is set properly.&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 14pt; LINE-HEIGHT: 115%"&gt;&amp;nbsp;Conclusion&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Even Rhinos tools could be not compatible between SVN versions; However most of the Rhino bits are used already in production environments and are very popular with a great community support. &lt;/P&gt;
&lt;P&gt;So, I would recommend taking Rhino Security in account if you already use NHibernate and if you need a similar model or your required model could be expressed with Rhino Security model.&lt;/P&gt;
&lt;P&gt;Notice: The code is tested with VS 2008 sp1 and Sql server 2005.&lt;/P&gt;
&lt;P&gt;Thank you, &lt;/P&gt;
&lt;P&gt;Artur Trosin &lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7022354" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/General+Software+Development/default.aspx">General Software Development</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/Open+Source/default.aspx">Open Source</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/Rhino+Security/default.aspx">Rhino Security</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/Rhino+Tools/default.aspx">Rhino Tools</category></item><item><title>ReSharper Tip:  Manual Code Reordering</title><link>http://weblogs.asp.net/arturtrosin/archive/2009/03/16/resharper-tip-manual-code-reordering.aspx</link><pubDate>Mon, 16 Mar 2009 10:33:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6968007</guid><dc:creator>Artur Trosin</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/arturtrosin/rsscomments.aspx?PostID=6968007</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/arturtrosin/commentapi.aspx?PostID=6968007</wfw:comment><comments>http://weblogs.asp.net/arturtrosin/archive/2009/03/16/resharper-tip-manual-code-reordering.aspx#comments</comments><description>&lt;P&gt;Most of you already know what &lt;A href="http://www.jetbrains.com/resharper/" mce_href="http://www.jetbrains.com/resharper/"&gt;ReSharper&lt;/A&gt; is and its power; its shortcuts can improve productivity drastically. That is why I really recommend learning its basic keyboard shortcuts for persons that have already ReSharper license. &lt;A href="http://www.jetbrains.com/resharper/documentation/feature_map.html" mce_href="http://www.jetbrains.com/resharper/documentation/feature_map.html"&gt;Here&lt;/A&gt; is full ReSharper keyboard shortcuts map: http://www.jetbrains.com/resharper/documentation/feature_map.html. &lt;/P&gt;
&lt;P&gt;I don’t want to go through all ReSharper keyboard shortcuts now but I want to show a Tip that I discovered for me few days ago named “&lt;B&gt;Manual Code Reordering&lt;/B&gt;”. For some of you it could not be new but for other it could be that is why I want to demonstrate them in the post. &lt;/P&gt;
&lt;P&gt;Let say you have a method or code block which you want to move UP or Down, usually you will cut it and will paste in right place, for that purpose ReSharper has its keyboard shortcut, so place your cursor on Method Name or other code block and press &lt;B&gt;Ctrl+Alt+Shift&lt;/B&gt; and holding the keys for a while your code block will become selected: &lt;/P&gt;
&lt;P&gt;&lt;IMG title="Method Move" style="WIDTH: 443px; HEIGHT: 226px" height=226 alt="Method Move" src="http://weblogs.asp.net/blogs/arturtrosin/ReSharperTip/MethodName.GIF" width=443 align=middle border=1 mce_src="http://weblogs.asp.net/blogs/arturtrosin/ReSharperTip/MethodName.GIF"&gt; &lt;/P&gt;
&lt;P&gt;Now while holding the keys you can move Up/Down the method within the class, you can do it with any other code blocks or (simple statements, code structure such as if/for/foreach etc..). &lt;/P&gt;
&lt;P&gt;Ok, but it is not all, if you place your cursor on operand then ReSharper will allow you to change operand order using Left/Right keyboard arrows, something like here: &lt;/P&gt;
&lt;P&gt;&lt;IMG title="Operator Move" style="WIDTH: 325px; HEIGHT: 261px" height=261 alt="Operator Move" src="http://weblogs.asp.net/blogs/arturtrosin/ReSharperTip/Operator.GIF" width=325 align=middle border=1 mce_src="http://weblogs.asp.net/blogs/arturtrosin/ReSharperTip/Operator.GIF"&gt; &lt;/P&gt;
&lt;P&gt;Maybe some will find this feature as not so useful (as other), but the shortcut save me some coding time. I hope you like it :). &lt;/P&gt;
&lt;P&gt;Ahh.. I use ReSharper 4.1. And my ReSharper Keyboard Schema is Intellij IDEA. (ReSharper-&amp;gt;Options-&amp;gt;General-&amp;gt;Intellij IDEA) &lt;/P&gt;
&lt;P&gt;PS: If you don’t find something to be useful then maybe you just wasn’t in situation when it would be useful? :) &lt;/P&gt;
&lt;P&gt;Thank you, &lt;/P&gt;
&lt;P&gt;Artur Trosin &lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6968007" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/ReSharper/default.aspx">ReSharper</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/Tips/default.aspx">Tips</category></item><item><title>With modern tools, Is a solution\project structure important?</title><link>http://weblogs.asp.net/arturtrosin/archive/2009/02/23/with-modern-tools-is-a-project-structure-important.aspx</link><pubDate>Mon, 23 Feb 2009 15:35:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6924235</guid><dc:creator>Artur Trosin</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/arturtrosin/rsscomments.aspx?PostID=6924235</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/arturtrosin/commentapi.aspx?PostID=6924235</wfw:comment><comments>http://weblogs.asp.net/arturtrosin/archive/2009/02/23/with-modern-tools-is-a-project-structure-important.aspx#comments</comments><description>In the post I would like to discuss importance of the solution (project) structure nowadays. So, is it really so important to create and maintain a well structured solution when you have such a powerful IDE like VS.NET and a 
    &lt;a href="http://www.jetbrains.com/resharper/"&gt;ReSharper&lt;/a&gt; plugin installed.  ReSharper for sure improves development work and minimizes development effort.  I‘ve seen number of times people saying that project structure is not important because such tool as ReSharper allows you to easily: navigate thru solution, project, classes ect…  refactor code with no pain without knowing where the classes are used, find any class, .dll, usages, inheritor, base…  within entire solution,  and many, many other cool things… even it will purpose to add a .dll reference if a class is in another project.
    &lt;p&gt;
        &amp;nbsp;OK... VS.NET + ReSharper are powerful... but that is enough?
    &lt;/p&gt;
    &lt;p&gt;
        &amp;nbsp;Let’s see… for small business projects in mostly cases importance of a good 
        solution\project structure is not high, because there will not be a very big 
        gain from that structure, same is for design decisions, tool set etc...
        &lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
    &lt;p &gt;
        For large projects “ReSharper shortcuts” are not enough. Why?&lt;/p&gt;
    &lt;p &gt;
        &amp;nbsp;Because it can help but it can’t do for you:&lt;/p&gt;
    &lt;ul&gt;
        &lt;li&gt;correctly define number of libraries and granularity &lt;/li&gt;
        &lt;li&gt;&amp;nbsp;correctly define references(dependencies) between libraries &lt;/li&gt;
        &lt;li&gt;&amp;nbsp;devise classes in namespaces - create intuitive folder structure &lt;/li&gt;
        &lt;li&gt;&amp;nbsp;say where fits new class\interface\enum\etc. and how to name it &lt;/li&gt;
        &lt;li&gt;&amp;nbsp;create project structure conventions (e.g. naming convention) &lt;/li&gt;
        &lt;li&gt;&amp;nbsp;define a big picture &lt;/li&gt;
        &lt;li&gt;&amp;nbsp;etc.&lt;/li&gt;
    &lt;/ul&gt;
    &lt;p&gt;
        enumerated above statements are very important for a larger projects. A 
        correctly set project structure can say a story about the project: where it is 
        now and what future of the project is. By future of the project I mean that is 
        more predictable. Change impact and major changes will more transparent. Self 
        explanatory project structure is very important, not only for beginners in a 
        project but also for persons that works for a module\project\layer separately. 
        It will allow easily decide changes, reuse, and share common language within 
        team members. Most of the development time we “read “ code\module\layer, so in 
        some stage of a project “write” time begins to depends on “read” time, good 
        project structure allows to concentrate only on one thing at a time, decrease 
        “read” time. Code responsibilities are more visible and more isolated(less 
        dependent), increasing reusability.&lt;/p&gt;
    &lt;p&gt;
        If a project structure doesn’t say anything about the project or you don’t know 
        where to fit new peace of code then it’s a sign that is something wrong, in this 
        case project should be refactored. Project structure is like a piece of code 
        that should be refactored when it doesn’t meet his needs, Yes, it is not so 
        easy… but is easier to spend hours\days on things that should take considerably 
        less effort?&lt;/p&gt;
    &lt;p class="MsoNormal"&gt;
        For small project, project structure it’s not so important, main purpose of 
        small projects is not maintenance but is to finish it quickly and often dirty. 
        As opposite, for large projects any decision is more important and its 
        consequences are more visible, these decisions are reflected in maintenance 
        time, nowadays maintenance is a key for large long term projects. So, project 
        structure is high-level description of a project that has more value for large 
        projects, because it can reduce maintenance costs.&lt;/p&gt;
    &lt;p&gt;
        I will not discuss “How to define a project structure” because it is not purpose 
        of the post but I will point to set of principles that can help you to organize 
        a correct project structure, so there a few general principles which are 
        overlooked behind
        &lt;a href="http://www.lostechies.com/blogs/chad_myers/archive/2008/03/07/pablo-s-topic-of-the-month-march-solid-principles.aspx"&gt;
        S.O.L.I.D. principles&lt;/a&gt;:
    &lt;/p&gt;
    &lt;p&gt;
        1) &lt;b&gt;The Reuse/Release Equivalence Principle (REP)&lt;/b&gt; - THE GRANULE OF REUSE 
        IS THE GRANULE OF RELEASE. ONLY COMPONENTS THAT ARE RELEASED THROUGH A TRACKING 
        SYSTEM CAN BE FFECTIVELY REUSED. THIS GRANULE IS THE PACKAGE.
    &lt;/p&gt;
    &lt;p&gt;
        2) &lt;b&gt;The Common Reuse Principle (CRP)&lt;/b&gt; - THE CLASSES IN A PACKAGE ARE REUSED 
        TOGETHER. IF YOU REUSE ONE OF THE CLASSES IN A PACKAGE, YOU REUSE THEM ALL.
    &lt;/p&gt;
    &lt;p&gt;
        3) &lt;b&gt;The Common Closure Principle (CCP)&lt;/b&gt; - THE CLASSES IN A PACKAGE SHOULD 
        BE CLOSED TOGETHER AGAINST THE SAME KINDS OF CHANGES. A CHANGE THAT AFFECTS A 
        PACKAGE AFFECTS ALL THE CLASSES IN THAT PACKAGE.
    &lt;/p&gt;
    &lt;p&gt;
        4) &lt;b&gt;The Acyclic Dependencies Principle (ADP)&lt;/b&gt; - THE DEPENDENCY STRUCTURE 
        BETWEEN PACKAGES MUST BE A DIRECTED ACYCLIC GRAPH (DAG). THAT IS, THERE MUST BE 
        NO CYCLES IN THE DEPENDENCY STRUCTURE.
    &lt;/p&gt;
    &lt;p&gt;
        5) &lt;b&gt;The Stable Dependencies Principle (SDP)&lt;/b&gt; - THE DEPENDENCIES BETWEEN 
        PACKAGES IN A DESIGN SHOULD BE IN THE DIRECTION OF THE STABILITY OF THE 
        PACKAGES. A PACKAGE SHOULD ONLY DEPEND UPON PACKAGES THAT ARE MORE STABLE THAT 
        IT IS.
    &lt;/p&gt;
    &lt;p&gt;
        6) &lt;b&gt;The Stable Abstractions Principle (SAP)&lt;/b&gt; - PACKAGES THAT ARE MAXIMALLY 
        STABLE SHOULD BE MAXIMALLY ABSTRACT. INSTABLE PACKAGES SHOULD BE CONCRETE. THE 
        ABSTRACTION OF A PACKAGE SHOULD BE IN PROPORTION TO ITS STABILITY.&lt;/p&gt;
    &lt;p&gt;
        All the principles can be found
        &lt;a href="http://objectmentor.com/resources/articles/granularity.pdf"&gt;here&lt;/a&gt;. 
        However, SOLID principles also could be applied for a solution\project 
        structure. Last two principles are described in
        &lt;a href="http://objectmentor.com/resources/articles/stability.pdf"&gt;more details 
        here&lt;/a&gt;.&lt;/p&gt;
    &lt;p &gt;
        &lt;b&gt;Conclusion&lt;/b&gt;
    &lt;/p&gt;
    &lt;p&gt;
        Organizing a project structure we define its: modularity, dependencies, common 
        language, conventions, cohesion level, first face of the application, etc.. how 
        a tool can replace it? It can only help…&lt;/p&gt;
    &lt;p&gt;
        &amp;nbsp;&lt;/p&gt;
    &lt;p&gt;
        Thank you, &lt;/p&gt;
    &lt;p&gt;
        Artur Trosin&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6924235" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/Design+Principles/default.aspx">Design Principles</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/Software+Architecture/default.aspx">Software Architecture</category></item><item><title>Domain Driven Design: Learning </title><link>http://weblogs.asp.net/arturtrosin/archive/2009/02/09/domain-driven-design-learning.aspx</link><pubDate>Mon, 09 Feb 2009 14:41:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6895706</guid><dc:creator>Artur Trosin</dc:creator><slash:comments>34</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/arturtrosin/rsscomments.aspx?PostID=6895706</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/arturtrosin/commentapi.aspx?PostID=6895706</wfw:comment><comments>http://weblogs.asp.net/arturtrosin/archive/2009/02/09/domain-driven-design-learning.aspx#comments</comments><description>&lt;DIV&gt;
&lt;P&gt;&lt;B&gt;1.&lt;/B&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;B&gt;Introduction&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;In the post I would like to help folks who want to improve their design skills and way of thinking by introducing in the Domain Driven Design (DDD) and provide a set of resources which I find useful. Also I will try to sort the resources because very often we can drop to learn something new only because we don’t see any sense or very little sense in reading a topic. That can happen because some resources are good for beginners other are good for more advanced folks, some persons need more practical examples for others &amp;nbsp;theory is enough to create a picture.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;2.&lt;/B&gt;&lt;B&gt;Why DDD?&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;There are few patterns to organize Domain Logic (or business logic):&lt;/P&gt;
&lt;P&gt;1)&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;A href="http://martinfowler.com/eaaCatalog/tableModule.html" mce_href="http://martinfowler.com/eaaCatalog/tableModule.html"&gt;Table Module&lt;/A&gt; - &lt;SPAN&gt;A single instance that handles the business logic for all rows in a database table or view.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;2)&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;A href="http://martinfowler.com/eaaCatalog/transactionScript.html"&gt;Transaction Script&lt;/A&gt; - &lt;SPAN&gt;Organizes business logic by procedures where each procedure handles a single request from the presentation.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;3)&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;A href="http://martinfowler.com/eaaCatalog/domainModel.html" mce_href="http://martinfowler.com/eaaCatalog/domainModel.html"&gt;Domain Model&lt;/A&gt; - An object model of the domain that incorporates both behavior and data.&lt;/P&gt;
&lt;P&gt;The patterns are described in more depth in &lt;B&gt;Patterns of Enterprise Application Architecture (P of EAA)&lt;/B&gt; book by Martin Fowler. In his book he shows that first two patterns are easier to start with than &lt;B&gt;Domain Model &lt;/B&gt;pattern, but by adding more complexity to domain logic, time to implement the complexity is much smaller when Domain Model is used. So the short conclusion from this is that Domain Model pattern is well suited to challenge complex domain needs (e.g. Financial Domains). Most of the software solutions in nowadays are designed to automate different domains, and a large number of systems are specific to particular needs of a business, so common software solutions in high competitive business less and less find their place in market. Why I’m discussing that? Because DDD is not only about the pure design but also teach how to abstract a complex Domain in a software solution where you will discover new ways of dealing with complexity, changes, communication, ubiquitous language etc.. Instead of making the system ugly, very hard to understand, un-maintainableand where any change in the system leads to a deeper legacy. &lt;/P&gt;
&lt;P&gt;DDD doesn’t ignore any other existing practice: Object Oriented Design, GoF patterns, &lt;A href="http://www.lostechies.com/blogs/chad_myers/archive/2008/03/07/pablo-s-topic-of-the-month-march-solid-principles.aspx" mce_href="http://www.lostechies.com/blogs/chad_myers/archive/2008/03/07/pablo-s-topic-of-the-month-march-solid-principles.aspx"&gt;S.O.L.I.D. design principles&lt;/A&gt;, TDD, Agile etc… DDD just complements them. To find right model and abstractions in complex scenarios still is needed to be a good Object Oriented modeler using various patterns and principles (not just DDD’s). &lt;/P&gt;
&lt;P&gt;&lt;B&gt;3.&lt;/B&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;B&gt;Where to start from? &lt;/B&gt;&lt;/P&gt;
&lt;P&gt;If you were interested in my DDD commercial then let’s go further, if not but still want to know more about DDD don’t leave the post because you can find more information interesting in provided resources :-). &lt;/P&gt;
&lt;P&gt;&amp;nbsp;First book which puts the light on DDD for larger community was &lt;B&gt;Domain-Driven Design: Tackling Complexity in the Heart of Software&lt;/B&gt; by &lt;B&gt;Eric Evans&lt;/B&gt;. The book describes very well what DDD is about and all aspects such as: ubiquitous  language, bounded context, patterns, design best practices, refactoring, domain modeling, how it works in Agile, and a lot of other good things. But even you will understand all very well what is described in the book which is not easy task, but… the book could leave a lot of questions from practical perspective (how those things works in practice) because the book is technology - agnostic. That can’t happen for advanced developers with strong background. For most of us reading theory without seeing a practical part of the things is very boring and even could lead to confusions. That is why I would recommend starting with a mini version of the Eric’s book, &lt;A href="http://www.infoq.com/news/2006/12/domain-driven-design" mce_href="http://www.infoq.com/news/2006/12/domain-driven-design"&gt;&lt;B&gt;Domain Driven Design Quickly&lt;/B&gt;&lt;/A&gt; which could be downloaded for free if you have a registration on the &lt;A href="http://www.infoq.com/" mce_href="http://www.infoq.com"&gt;infoq site&lt;/A&gt;. &lt;/P&gt;
&lt;P&gt;There are also good Eric’s presentations which you can start with: &lt;/P&gt;
&lt;P&gt;1)&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;A href="http://www.infoq.com/presentations/model-to-work-evans" mce_href="http://www.infoq.com/presentations/model-to-work-evans"&gt;DDD: putting the model to work&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;2)&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;A href="http://www.infoq.com/presentations/strategic-design-evans" mce_href="http://www.infoq.com/presentations/strategic-design-evans"&gt;Eric Evans on DDD: Strategic Design&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;3)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;A class="" title="Eric Evans: What I've learned about DDD since the book" href="http://domaindrivendesign.org/library/evans_2009_1" mce_href="http://domaindrivendesign.org/library/evans_2009_1"&gt;Eric Evans: What I've learned about DDD since the book&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;4)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;A class="" title="Strategic Design &amp;amp; Responsibility Traps" href="http://skillsmatter.com/podcast/design-architecture/keynote-domain-drive-design" mce_href="http://skillsmatter.com/podcast/design-architecture/keynote-domain-drive-design"&gt;Strategic Design &amp;amp; Responsibility Traps&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.infoq.com/" mce_href="http://www.infoq.com/"&gt;Infoq&lt;/A&gt; has many other good &lt;A href="http://www.infoq.com/domain-driven-design" mce_href="http://www.infoq.com/domain-driven-design"&gt;presentations, articles and interviews&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;So if you already have some theoretical background and where interested in the DDD then to clarify practical things of the organization of a software solution checkout &lt;B&gt;.NET Domain-Driven Design with C#, Problem – Design – Solution&lt;/B&gt; book by &lt;B&gt;Tim McCarthy&lt;/B&gt;. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;From the book you can learn in practice:&lt;/P&gt;
&lt;P&gt;1)&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;How the process is going from requirements to design and then to a code solution&lt;/P&gt;
&lt;P&gt;2)&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;How to organize architectural solution and layers&lt;/P&gt;
&lt;P&gt;3)&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;How common DDD patterns and practices are applied &lt;/P&gt;
&lt;P&gt;4)&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;How to build a little infrastructure framework for DDD&lt;/P&gt;
&lt;P&gt;5)&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;How to isolate Domain Model from infrastructure&lt;/P&gt;
&lt;P&gt;6)&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Etc...&lt;/P&gt;
&lt;P&gt;This is very good DDD practical book, even there are not ready to use implementations for production, but his ideas and concepts can be applied widely. &amp;nbsp;The book starts with just requirements and finally at the end of the book the author provides a sample application in .NET 3.5 which you can check out on &lt;A href="http://www.codeplex.com/dddpds" mce_href="http://www.codeplex.com/dddpds"&gt;codeplex&lt;/A&gt;. &lt;/P&gt;
&lt;P&gt;All the concepts of the book are built mainly on three books: Martin’s PoEAA, Eric’s Book, and &lt;B&gt;Jimmy Nilsson’s&lt;/B&gt; book &lt;B&gt;Applying Domain - Driven Design and Patterns&lt;/B&gt;. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;However DDD is not only practical solution or patterns, it is a mindset and discipline, and there are many other things which should be considered if you are decided to go on DDD way such as: &amp;nbsp;focusing on a model and importance of a model, ubiquitous language, bounded context, process of modeling, knowledge sharing, refactoring, strategic design, etc... that is why I strongly recommend to return back to the Eric’s book after reading Tim’s book. At the stage Eric’s book will give you more value and more concepts which are better understudied.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;DDD is not tied to any technology however it will be hard to accomplish it without good tools and practices in your toolkit such as TDD, ORM, Persistence Ignorance (PI), Inversion of Control (IoC), and Aspect Oriented Programming (AOP), that doesn’t mean that all of them always are absolutely necessary but they can help to implement a real DDD solution. Particularly those tools can help to isolate domain model from infrastructure, the isolation is a key of success in DDD. Nilsson’s book covers those tools and techniques that are practical guide to implement maintainable and robust DDD systems. Nilsson also shows how to link &lt;A href="http://martinfowler.com/eaaCatalog/index.html" mce_href="http://martinfowler.com/eaaCatalog/index.html"&gt;enterprise patterns&lt;/A&gt; and DDD concepts in one well structured system in the same time showing how modern technologies and techniques can be useful rather an obstacle. &lt;/P&gt;
&lt;P s&gt;&lt;B&gt;4.&lt;/B&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;B&gt;DDD related topics&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;Other very tightly related topic is Distributed DDD (DDDD). DDDD is DDD in distributed scenarios. &amp;nbsp;There are not so many resources on the DDDD, in few words DDDD is about messaging and Domain Driven Design, &lt;A href="http://en.wikipedia.org/wiki/Command-Query_Separation" mce_href="http://en.wikipedia.org/wiki/Command-Query_Separation"&gt;Command Query Separation (CQS)&lt;/A&gt; concept helps to combine DDD and messaging. &lt;A href="http://codebetter.com/blogs/gregyoung/" mce_href="http://codebetter.com/blogs/gregyoung/"&gt;Greg Young&lt;/A&gt; says that he &lt;A href="http://www.infoq.com/interviews/greg-young-ddd" mce_href="http://www.infoq.com/interviews/greg-young-ddd"&gt;is writing a book related to DDDD&lt;/A&gt;. More theory about CQR &lt;A class="" href="http://elegantcode.com/2009/11/11/cqrs-la-greg-young/" mce_href="http://elegantcode.com/2009/11/11/cqrs-la-greg-young/"&gt;here&lt;/A&gt;&amp;nbsp;and sample &lt;A class="" href="http://blog.fohjin.com/blog/2009/11/3/CQRS_a_la_Greg_Young_example_code" mce_href="http://blog.fohjin.com/blog/2009/11/3/CQRS_a_la_Greg_Young_example_code"&gt;here&lt;/A&gt; .&lt;/P&gt;
&lt;P&gt;SOA and DDD is also another great topic which is very often discussed by &lt;A href="http://www.udidahan.com/" mce_href="http://www.udidahan.com/"&gt;Udi Dahan&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;B&gt;5.&lt;/B&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;B&gt;DDD patterns, concepts and terms&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;In real world DDD implementation are used a set of patterns, a part of them are described in Eric’s book, but as I already mentioned that doesn’t mean other OO principles and pattern are not applicable, such as &lt;A href="http://en.wikipedia.org/wiki/Design_Patterns" mce_href="http://en.wikipedia.org/wiki/Design_Patterns"&gt;GoF patterns&lt;/A&gt;,&amp;nbsp; &lt;A href="http://martinfowler.com/eaaCatalog/index.html" mce_href="http://martinfowler.com/eaaCatalog/index.html"&gt;PoEAA&lt;/A&gt;, &lt;A href="http://www.enterpriseintegrationpatterns.com/" mce_href="http://www.enterpriseintegrationpatterns.com/"&gt;Enterprise Integration Patterns&lt;/A&gt;, etc…&lt;/P&gt;
&lt;P&gt;Here are few of them:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;BLOCKQUOTE&gt;
&lt;BLOCKQUOTE&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;a)&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;A class="" href="http://domaindrivendesign.org/node/135" mce_href="http://domaindrivendesign.org/node/135"&gt;Value Object&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;b)&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;A href="http://www.martinfowler.com/bliki/EvansClassification.html" mce_href="http://www.martinfowler.com/bliki/EvansClassification.html"&gt;Entity&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;c)&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;A href="http://www.lostechies.com/blogs/jimmy_bogard/archive/2008/08/21/services-in-domain-driven-design.aspx" mce_href="http://www.lostechies.com/blogs/jimmy_bogard/archive/2008/08/21/services-in-domain-driven-design.aspx"&gt;Service&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;d)&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;A class="" href="http://codeidol.com/csharp/domain-driven-design/A-Model-Expressed-in-Software/a.-Packages)/" mce_href="http://codeidol.com/csharp/domain-driven-design/A-Model-Expressed-in-Software/a.-Packages)/"&gt;Module&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;e)&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;A class="" href="http://domaindrivendesign.org/node/88" mce_href="http://domaindrivendesign.org/node/88"&gt;Aggregate&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;f)&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;A href="http://martinfowler.com/eaaCatalog/repository.html" mce_href="http://martinfowler.com/eaaCatalog/repository.html"&gt;Repository&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;g)&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;A href="http://blogs.interknowlogy.com/timmccarthy/archive/2007/01/22/10863.aspx" mce_href="http://blogs.interknowlogy.com/timmccarthy/archive/2007/01/22/10863.aspx"&gt;Specification&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;h)&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;A href="http://martinfowler.com/eaaCatalog/layerSupertype.html" mce_href="http://martinfowler.com/eaaCatalog/layerSupertype.html"&gt;Layer Supertype&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;i)&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;A href="http://martinfowler.com/eaaCatalog/identityMap.html" mce_href="http://martinfowler.com/eaaCatalog/identityMap.html"&gt;Identity Map&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;j)&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;A href="http://domaindrivendesign.org/discussion/messageboardarchive/Factories.html" mce_href="http://domaindrivendesign.org/discussion/messageboardarchive/Factories.html"&gt;Factories&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;k)&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;A href="http://martinfowler.com/eaaCatalog/unitOfWork.html" mce_href="http://martinfowler.com/eaaCatalog/unitOfWork.html"&gt;Unit of Work(UoW)&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;l)&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/cc707904.aspx" mce_href="http://msdn.microsoft.com/en-us/library/cc707904.aspx"&gt;Inversion of Control(IoC)&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;m)&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;A href="http://en.wikipedia.org/wiki/Aspect-oriented_programming"&gt;Aspect Oriented Programming(AOP)&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;n)&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;A class="" href="http://domaindrivendesign.org/node/91" mce_href="http://domaindrivendesign.org/node/91"&gt;Bounded Context&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;o)&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;A class="" href="http://domaindrivendesign.org/node/132" mce_href="http://domaindrivendesign.org/node/132"&gt;Ubiquitous language&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;p)&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;A href="http://en.wikipedia.org/wiki/Object-relational_mapping" mce_href="http://en.wikipedia.org/wiki/Object-relational_mapping"&gt;Object-relational mapping(ORM)&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;q)&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;A href="http://www.martinfowler.com/bliki/AnemicDomainModel.html" mce_href="http://www.martinfowler.com/bliki/AnemicDomainModel.html"&gt;Anemic Domain Model anti pattern&lt;/A&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;/BLOCKQUOTE&gt;&lt;/BLOCKQUOTE&gt;&lt;/BLOCKQUOTE&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;B&gt;6.&lt;/B&gt;&lt;SPAN&gt;&lt;B&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/B&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;B&gt;Sample applications&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;Good DDD samples is very hard to find, that is not because they doesn’t exists but because real DDD power is discovered in complex domains. Mostly DDD projects with complex domains are commercial projects. However there are few projects where you can catch some ideas to have implementation view of DDD patterns.&lt;/P&gt;
&lt;P&gt;Here are few of them:&lt;/P&gt;
&lt;P&gt;1) Tim’s project, &lt;A href="http://www.codeplex.com/dddpds" mce_href="http://www.codeplex.com/dddpds"&gt;the project&lt;/A&gt; is described in details by his book. He not only describes patterns used but also a domain model implementation from DDD point of view.&lt;/P&gt;
&lt;P&gt;The project is also interesting because he uses new technologies like .NET 3.5, WPF, and shows how to implicate Model View View-Model (MVVM) pattern to adapt domain model to view and take advantage of powerful data binding.&amp;nbsp; Also I like how he finds common logic and refactor it to Template Pattern.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;
&lt;P&gt;2) Next project which I strongly recommend to take a look is Yves Goeleven's &lt;A href="http://www.goeleven.com/resources/architecture/DDD/DDDSeries-Example.zip" mce_href="http://www.goeleven.com/resources/architecture/DDD/DDDSeries-Example.zip"&gt;sample application&lt;/A&gt;; he also has posts where he &lt;A href="http://www.goeleven.com/blog/entryDetail.aspx?entry=89" mce_href="http://www.goeleven.com/blog/entryDetail.aspx?entry=89"&gt;describes&lt;/A&gt; his sample application and DDD concepts. Another his sample application advantage is that the sample is based on his little and clean &lt;A href="http://www.goeleven.com/resources/architecture/DDD/DDDSeries-Framework.zip" mce_href="http://www.goeleven.com/resources/architecture/DDD/DDDSeries-Framework.zip"&gt;framework&lt;/A&gt; if I can name so. The framework source code is also available. Take attention to how he uses specification pattern together with repositories.&lt;/P&gt;
&lt;P&gt;3) Billy McCafferty also has a very interesting open source framework which is focused to DDD, named &lt;A href="http://code.google.com/p/sharp-architecture/" mce_href="http://code.google.com/p/sharp-architecture/"&gt;S#arp Architecture&lt;/A&gt;. He also has a &lt;A href="http://www.codeproject.com/KB/architecture/NHibernateBestPractices.aspx" mce_href="http://www.codeproject.com/KB/architecture/NHibernateBestPractices.aspx"&gt;very good description&lt;/A&gt; of many best practices which are encapsulated by the framework. The framework mainly is targeted to ASP.NET MVC and NHibernate.&lt;/P&gt;
&lt;P&gt;4) &lt;A class="" href="http://code.google.com/p/ndddsample/" mce_href="http://code.google.com/p/ndddsample/"&gt;C# Domain-Driven Design sample application&amp;nbsp;( ndddsample )&lt;/A&gt;, Im also involved in the project, the project&amp;nbsp;is in mature&amp;nbsp;stage, and has&amp;nbsp;a lot of&amp;nbsp;DDD patterns and concepts covered from practical perspective. One of the main targets of the project is to demonstrate a practical implementation of the building block patterns described in the Eric Evans book based on a real but simplified cargo domain (which is also used as example in Eric Evans’ book). &lt;/P&gt;
&lt;P&gt;The project is based on a joint effort by Eric Evans' company Domain Language and the Swedish software consulting company Citerus. &lt;/P&gt;
&lt;P&gt;The purpose of the project is: &lt;/P&gt;
&lt;P&gt;-To show practical side of DDD using .net framework &lt;/P&gt;
&lt;P&gt;- Incrementally adjust the code and apply .net conventions and practices &lt;/P&gt;
&lt;P&gt;- Use latest .net tools, technologies and software development methodologies that are widely used and discussed within alt.net group &lt;/P&gt;
&lt;P&gt;- To provide an "how-to" example for implementing a typical DDD application &lt;/P&gt;
&lt;P&gt;- To show a decent way to do it(but not the way to do it). Eventually, the same design could be re-implemented on various popular platforms, to give the same assistance to people working on those platforms,and also help those who must transition between the platforms. &lt;/P&gt;
&lt;P&gt;- To support discussion of implementation practices. Variations could show trade-offs of alternative approaches, helping the community to clarify and refine best practices for building DDD applications.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A class="" href="http://code.google.com/p/ndddsample/" mce_href="http://code.google.com/p/ndddsample/"&gt;here is more info&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;5) &lt;A class="" title="MyShop - DDDD Sample Application" href="http://myshop.codeplex.com/" mce_href="http://myshop.codeplex.com/"&gt;MyShop - DDDD Sample Application&lt;/A&gt; - This is a sample application to proof the concept of DDDD, better known as CQS &amp;amp; event storage an extension to DDD. This concept was first mentioned by Gregory Young and since then it created a huge buzz in the community&lt;/P&gt;
&lt;P&gt;&lt;B&gt;7.&lt;/B&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;B&gt;Domain Driven Design Recommended &lt;/B&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;B&gt;Official site&lt;/B&gt; - &lt;A href="http://domaindrivendesign.org/" mce_href="http://domaindrivendesign.org/"&gt;http://domaindrivendesign.org/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Discussion Group&lt;/B&gt; - &lt;A href="http://tech.groups.yahoo.com/group/domaindrivendesign/" mce_href="http://tech.groups.yahoo.com/group/domaindrivendesign/"&gt;http://tech.groups.yahoo.com/group/domaindrivendesign/&lt;/A&gt; this is very old group, very good source of ideas, place for discussion of all kind DDD related problems. Your question could be answered by many experienced in DDD people, even by Eric Evans :-).&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Jimmy Bogard&lt;/B&gt; - &lt;A href="http://www.lostechies.com/blogs/jimmy_bogard/default.aspx" mce_href="http://www.lostechies.com/blogs/jimmy_bogard/default.aspx"&gt;http://www.lostechies.com/blogs/jimmy_bogard/default.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Colin Jack&lt;/B&gt; - &lt;A href="http://colinjack.blogspot.com/" mce_href="http://colinjack.blogspot.com/"&gt;http://colinjack.blogspot.com/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Greg Young&lt;/B&gt; - &lt;A href="http://codebetter.com/blogs/gregyoung/default.aspx" mce_href="http://codebetter.com/blogs/gregyoung/default.aspx"&gt;http://codebetter.com/blogs/gregyoung/default.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Casey Charlton&lt;/STRONG&gt; - &lt;A href="http://devlicio.us/blogs/casey/"&gt;http://devlicio.us/blogs/casey/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Udi Dahan&lt;/B&gt; - &lt;A href="http://www.udidahan.com/"&gt;http://www.udidahan.com/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;B&gt;An Introduction To Domain-Driven Design&lt;/B&gt;- &lt;A href="http://msdn.microsoft.com/en-us/magazine/dd419654.aspx" mce_href="http://msdn.microsoft.com/en-us/magazine/dd419654.aspx"&gt;http://msdn.microsoft.com/en-us/magazine/dd419654.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;B&gt;8.&lt;/B&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;B&gt;Conclusion&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;If you want to open your Object Oriented horizons in complex enterprise systems and discover new development and design ways then DDD is for you.&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;Artur Trosin&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6895706" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/DDD/default.aspx">DDD</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/Design+Principles/default.aspx">Design Principles</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/Patterns/default.aspx">Patterns</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/Software+Architecture/default.aspx">Software Architecture</category></item><item><title>Separation of Concern vs Single Responsibility Principle ( SoC vs SRP )</title><link>http://weblogs.asp.net/arturtrosin/archive/2009/01/26/separation-of-concern-vs-single-responsibility-principle-soc-vs-srp.aspx</link><pubDate>Mon, 26 Jan 2009 14:52:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6860732</guid><dc:creator>Artur Trosin</dc:creator><slash:comments>9</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/arturtrosin/rsscomments.aspx?PostID=6860732</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/arturtrosin/commentapi.aspx?PostID=6860732</wfw:comment><comments>http://weblogs.asp.net/arturtrosin/archive/2009/01/26/separation-of-concern-vs-single-responsibility-principle-soc-vs-srp.aspx#comments</comments><description>&lt;BLOCKQUOTE&gt;
&lt;P mce_keep="true"&gt;These two great principals that stands on the base of many design and architecture decisions.&amp;nbsp; We very often meet these principals in book, articles, blogs, etc...&amp;nbsp; And main question which risen in my head was what they really all about and how they relate to each other?&amp;nbsp; These two principles are totally discrete from each other or their core principle is the same? &lt;BR&gt;Just to remember what these two principles means lets read following statements which defines the each of them:&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;Separation of Concerns (SoC)&lt;/STRONG&gt; – is the process of breaking a computer program into distinct features that overlap in functionality as little as possible. A concern is any piece of interest or focus in a program. Typically, concerns are synonymous with features or behaviors.&lt;BR&gt;&lt;A href="http://en.wikipedia.org/wiki/Separation_of_concerns" mce_href="http://en.wikipedia.org/wiki/Separation_of_concerns"&gt;http://en.wikipedia.org/wiki/Separation_of_concerns&lt;/A&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;Single Responsibility Principle (SRP)&lt;/STRONG&gt; – every object should have a single responsibility, and that all its services should be narrowly aligned with that responsibility. On some level Cohesion is considered as synonym for SRP.&lt;BR&gt;&lt;A href="http://en.wikipedia.org/wiki/Single_responsibility_principle" mce_href="http://en.wikipedia.org/wiki/Single_responsibility_principle"&gt;http://en.wikipedia.org/wiki/Single_responsibility_principle&lt;/A&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;From the first sight very simple and easy to understand. The principles really have a lot in common and in general they both talk about decoupling in distinct Logical Units with well defined Boundaries (responsibilities). Logical Unit and Boundaries could be very abstract or concrete, and the boundaries depend on the &lt;STRONG&gt;context&lt;/STRONG&gt; of the problem which you are trying to solve. &lt;/P&gt;
&lt;P&gt;The separation allows:&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;UL&gt;
&lt;LI&gt;
&lt;DIV mce_keep="true"&gt;To allow people to work on individual pieces of the system in isolation;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV mce_keep="true"&gt;To facilitate reusability;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV mce_keep="true"&gt;To ensure the maintainability of a system;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV mce_keep="true"&gt;To add new features easily;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV mce_keep="true"&gt;To enable everyone to better understand the system;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV mce_keep="true"&gt;Etc...;&lt;/DIV&gt;&lt;/LI&gt;
&lt;P mce_keep="true"&gt;And of course, SoC is not limited to Architecture Layers, it’s also applied on many other things, such as:&amp;nbsp; an object that could represent a concern from language point view, SOA can separate concerns into services, separating behaviour as concern in logical units, etc...&lt;BR&gt;If to discuss further about similarities, SRP mostly means the same thing as SoC for layered architecture example. &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; However, SRP was re-interpreted by Uncle Bob with the definition “THERE SHOULD NEVER BE MORE THAN ONE REASON FOR A CLASS TO CHANGE”.&amp;nbsp; By the definition, SRP was narrowed down to class level. &lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;The “narrowed” SRP definition also could leave a lot of questions, how we can make sure that our new class really has one responsibility and there is only one reason to change?&amp;nbsp; Similar question we could raise for SoC… What is for sure is that is not one answer, but in general the answer is that there is not a Rule and all depends on the context of the problem. You can find an answer by yourself by answering next questions:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;
&lt;DIV mce_keep="true"&gt;&amp;nbsp;What is really the &lt;STRONG&gt;boundary&lt;/STRONG&gt; of the Responsibility that you are trying to separate?&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV mce_keep="true"&gt;&amp;nbsp;What is really the &lt;STRONG&gt;boundary&lt;/STRONG&gt; of the Concern that you are trying separate?&lt;/DIV&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P mce_keep="true"&gt;In real-world applications is mostly impossible to implement an ideal solution, trying to solve by one principle you can break another, such as YAGNI or over design…&lt;BR&gt;Is very important to notice that:&amp;nbsp; do not shift all the principles to extremes, because in real cases is impossible to achieve them from all point of views. So is very important to apply them from a certain and most meaningful&amp;nbsp;&amp;nbsp; angle. &lt;BR&gt;&amp;nbsp;The principles on certain level have similarities but on another level they are different things, let’s find out it by an example. &lt;BR&gt;Let’s suppose we have following user story, “&lt;EM&gt;user should be able set screen background color because the color should be customizable for any logged on user, so user access must be checked before color is set&lt;/EM&gt;”.&lt;/P&gt;
&lt;P mce_keep="true"&gt;Here is very raw implementation (just for demonstration purpose) of the requirement:&lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;internal&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;class&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;UserSettingsService&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;{&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; SetBackgroundColor(&lt;SPAN style="COLOR: #2b91af"&gt;ConsoleColor&lt;/SPAN&gt; color)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; CheckAccess();&lt;/P&gt;
&lt;P style="MARGIN: 0px" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;.BackgroundColor = color;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;.WriteLine(&lt;SPAN style="COLOR: #a31515"&gt;"- Color is changed..."&lt;/SPAN&gt;);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;static&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; CheckAccess()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; (IsCurrentUserLogedIn())&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;throw&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;SecurityException&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #a31515"&gt;"Can't change color."&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; + &lt;SPAN style="COLOR: #a31515"&gt;"The User is not Authenticated in the system"&lt;/SPAN&gt;);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;static&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;bool&lt;/SPAN&gt; IsCurrentUserLogedIn()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;Thread&lt;/SPAN&gt;.CurrentPrincipal.Identity.IsAuthenticated;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;}&lt;/P&gt;&lt;/DIV&gt;&lt;!--EndFragment--&gt;
&lt;P mce_keep="true"&gt;&lt;BR&gt;Main purpose of the SetBackgroundColor method is to set new background color but before to set a new color we check if the user has access. Security access checking is encapsulated by CheckAccess method. After short explanation, let’s go back to our lovely SoC and SRP, on method level each method has its own concern and single responsibility. However on class level they are not, the class is far from to be a cohesive one, it encapsulates Security checks and changing screen color logic. But what if we need to do same check in another classes? then the Check Access logic is duplicated OR we can change the Check Access to public and use the class. Of course, both ways are not the best practices.&lt;BR&gt;&amp;nbsp;Let’s do next step of refactoring and separate each class with its own responsibilities:&lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;internal&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;class&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;UserSettingsService&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;{&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; SetBackgroundColor(&lt;SPAN style="COLOR: #2b91af"&gt;ConsoleColor&lt;/SPAN&gt; color)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;SecurityService&lt;/SPAN&gt;.CheckAccess();&lt;/P&gt;
&lt;P style="MARGIN: 0px" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;.BackgroundColor = color;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;.WriteLine(&lt;SPAN style="COLOR: #a31515"&gt;"- Color is changed..."&lt;/SPAN&gt;);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;}&lt;/P&gt;
&lt;P style="MARGIN: 0px" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;internal&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;class&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;SecurityService&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;{&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &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;void&lt;/SPAN&gt; CheckAccess()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; (IsCurrentUserLogedIn())&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;throw&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;SecurityException&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #a31515"&gt;"Can't change color."&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; + &lt;SPAN style="COLOR: #a31515"&gt;"The User is not Authenticated in the system"&lt;/SPAN&gt;);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;static&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;bool&lt;/SPAN&gt; IsCurrentUserLogedIn()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;Thread&lt;/SPAN&gt;.CurrentPrincipal.Identity.IsAuthenticated;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp;&amp;nbsp; &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;}&lt;/P&gt;&lt;/DIV&gt;
&lt;P mce_keep="true"&gt;&lt;!--EndFragment--&gt;Now the classes are separated so each class has its own responsibility:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;
&lt;DIV mce_keep="true"&gt;UserSettingsService - to set background&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV mce_keep="true"&gt;SecurityService - to check security&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/DIV&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P mce_keep="true"&gt;which increases their reusability and therefore maintainability. &lt;BR&gt;So in the last example SRP is not broken because each class has its own well defined responsibility. From another perspective if we take the security checks as infrastructure related concerns and changing color as domain concerns then SoC is broken, because set color invokes security checks instead just setting the color. We can avoid pollution of the domain logic with infrastructure stuff, by applying Virtual Proxy Pattern which will wrap &lt;EM&gt;UserSettingsService&lt;/EM&gt; class and will perform security checks before “real” &lt;EM&gt;SetBackgroundColor&lt;/EM&gt; method is invoked. &lt;/P&gt;
&lt;P mce_keep="true"&gt;The security checks such in the example above are considered Cross-Cutting Concerns and that is why &lt;STRONG&gt;AOP&lt;/STRONG&gt; (Aspect Oriented Programming) was invented for. AOP tries to separate such concerns in separate component(s) and apply and reuse the component(s) without introducing dependencies on the components making easier maintenance. &lt;BR&gt;Conclusion, the SRP and SoC principles have something in common but in the same time they have some differences, also they should be viewed as an advice and not a rule, a developer should feel when and how to apply and do abstract concerns and responsibilities for a problem correctly. &lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;BR&gt;[&lt;STRONG&gt;Note&lt;/STRONG&gt;: I assume that provided example could not be ideal or the best one but I hope at least it shows my idea.]&lt;/P&gt;
&lt;P mce_keep="true"&gt;Thank you,&lt;/P&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Artur Trosin&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/UL&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6860732" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/Design+Principles/default.aspx">Design Principles</category></item><item><title>The M is MVC or MVP IS or IS NOT a Domain Model Object</title><link>http://weblogs.asp.net/arturtrosin/archive/2008/12/16/the-m-is-mvc-or-mvp-is-or-is-not-a-domain-model-object.aspx</link><pubDate>Mon, 15 Dec 2008 22:04:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6788889</guid><dc:creator>Artur Trosin</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/arturtrosin/rsscomments.aspx?PostID=6788889</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/arturtrosin/commentapi.aspx?PostID=6788889</wfw:comment><comments>http://weblogs.asp.net/arturtrosin/archive/2008/12/16/the-m-is-mvc-or-mvp-is-or-is-not-a-domain-model-object.aspx#comments</comments><description>Hi,
&lt;br&gt;
On Domain Driven Design  yahoo discussion group was raised a very interesting question, what is really the M mean from Model-View-Controller and its derivate brother Model-View-Presenter patterns’ perspective.
&lt;br&gt;
From a very long discussion we can see that there lots of opinions on this matter,  and there are so many opinions because of different sources which describe the pattern(s) with its little but important differences,  many technologies and frameworks which apply the pattern(s) and various developers experience with its specifics, etc.. 
&lt;br&gt;
Here is the link: 
&lt;br&gt;
http://tech.groups.yahoo.com/group/domaindrivendesign/message/9176
&lt;br&gt;&lt;br&gt;
Any thoughts?
&lt;br&gt;&lt;br&gt;
Best Regards,
&lt;br&gt;
Artur Trosin
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6788889" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/DDD/default.aspx">DDD</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/General+Software+Development/default.aspx">General Software Development</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/Patterns/default.aspx">Patterns</category></item><item><title>How Extension Methods can increase readability</title><link>http://weblogs.asp.net/arturtrosin/archive/2008/12/01/how-extension-methods-can-increase-readability.aspx</link><pubDate>Mon, 01 Dec 2008 14:16:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6761739</guid><dc:creator>Artur Trosin</dc:creator><slash:comments>9</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/arturtrosin/rsscomments.aspx?PostID=6761739</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/arturtrosin/commentapi.aspx?PostID=6761739</wfw:comment><comments>http://weblogs.asp.net/arturtrosin/archive/2008/12/01/how-extension-methods-can-increase-readability.aspx#comments</comments><description>&lt;DIV class=Section1&gt;
&lt;P class=MsoNormal style="MARGIN-LEFT: 0in; TEXT-INDENT: 0in"&gt;&lt;SPAN lang=EN-GB&gt;In day by day work, a developer has to branch their logic checking for null, and it is obvious that checks for null are the most common checks in most projects.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-LEFT: 0in; TEXT-INDENT: 0in"&gt;&lt;SPAN lang=EN-GB&gt;The checks can be avoided by using &lt;A href="http://www.refactoring.com/catalog/introduceNullObject.html" mce_href="http://www.refactoring.com/catalog/introduceNullObject.html"&gt;Null Object Pattern&lt;/A&gt; or &lt;A href="http://martinfowler.com/apsupp/spec.pdf" mce_href="http://martinfowler.com/apsupp/spec.pdf"&gt;Specification Pattern&lt;/A&gt; both well documented by Martin Fowler. But the Null Object pattern can’t be reused everywhere, so still in some cases the null checks will exists. Specification pattern I consider is quite heavy just for null checks.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-LEFT: 0in; TEXT-INDENT: 0in"&gt;&lt;SPAN lang=EN-GB&gt;Let’s suppose that in UI layer we should display a list of users which have LastLoginDate null and has a Role assigned (Role property is not null):&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="COLOR: blue; FONT-FAMILY: 'Courier New'"&gt;void&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt; DisplayUserList()&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;IList&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;User&lt;/SPAN&gt;&amp;gt; userList = UserService.GetAll();&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; (userList == &lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;&amp;nbsp;|| userList.Count&amp;nbsp;== 0)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;foreach&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #2b91af"&gt;User&lt;/SPAN&gt; user &lt;SPAN style="COLOR: blue"&gt;in&lt;/SPAN&gt; userList)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; (user.LastLoginDate == &lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt; &amp;amp;&amp;amp; user.Role != &lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DisplayUser(user);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-LEFT: 0in; TEXT-INDENT: 0in"&gt;&lt;SPAN lang=EN-GB&gt;So as we can see there are boring and not readable checks, we can perform a small but useful refactoring and make a little bit more readable (and easier to type &lt;/SPAN&gt;&lt;SPAN lang=EN-GB style="FONT-FAMILY: Wingdings"&gt;J&lt;/SPAN&gt;&lt;SPAN lang=EN-GB&gt; ) by introducing few &lt;A href="http://msdn.microsoft.com/en-us/library/bb383977.aspx" mce_href="http://msdn.microsoft.com/en-us/library/bb383977.aspx"&gt;extension methods&lt;/A&gt;:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-LEFT: 0in; TEXT-INDENT: 0in"&gt;&lt;SPAN lang=EN-GB&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN lang=EN-GB style="COLOR: blue; FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue; FONT-FAMILY: 'Courier New'"&gt;static&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt; &lt;SPAN style="COLOR: blue"&gt;bool&lt;/SPAN&gt; IsNull(&lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; obj)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; obj == &lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;static&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;bool&lt;/SPAN&gt; IsNullOrEmpty&amp;lt;T&amp;gt;(&lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;ICollection&lt;/SPAN&gt;&amp;lt;T&amp;gt; list)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; list.IsNull() || list.Count == 0;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;static&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;bool&lt;/SPAN&gt; IsNotNull(&lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; obj)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; !obj.IsNull();&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-LEFT: 0in; TEXT-INDENT: 0in"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-LEFT: 0in; TEXT-INDENT: 0in"&gt;&lt;SPAN lang=EN-GB style="COLOR: #99cc00"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN lang=EN-GB&gt;Now the code looks as follows:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-LEFT: 0in; TEXT-INDENT: 0in"&gt;&lt;SPAN lang=EN-GB&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="COLOR: blue; FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; void&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt; ExtentionDisplayUserList()&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;{&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;IList&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;User&lt;/SPAN&gt;&amp;gt; userList = UserService.GetAll();&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; (userList.IsNullOrEmpty())&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;foreach&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #2b91af"&gt;User&lt;/SPAN&gt; user &lt;SPAN style="COLOR: blue"&gt;in&lt;/SPAN&gt; userList)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; (user.LastLoginDate.IsNull() &amp;amp;&amp;amp; user.Role.IsNotNull())&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DisplayUser(user);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; TEXT-ALIGN: left" align=left&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-LEFT: 0in; TEXT-INDENT: 0in"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt; &lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-LEFT: 0in; TEXT-INDENT: 0in"&gt;&lt;SPAN lang=EN-GB&gt;The conclusion is that extension methods not only can extend objects but also our imagination &lt;/SPAN&gt;&lt;SPAN lang=EN-GB style="FONT-FAMILY: Wingdings"&gt;J&lt;/SPAN&gt;&lt;SPAN lang=EN-GB&gt; “how we can improve our code”.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-LEFT: 0in; TEXT-INDENT: 0in"&gt;&lt;SPAN lang=EN-GB&gt;Note: The code above is not intended to show how is better to design but only to show how extension method can increase readability. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-LEFT: 0in; TEXT-INDENT: 0in"&gt;&lt;SPAN lang=EN-GB&gt;Thanks for your reading &lt;/SPAN&gt;&lt;SPAN lang=EN-GB style="FONT-FAMILY: Wingdings"&gt;J&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN lang=EN-GB&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6761739" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/Code+Readability/default.aspx">Code Readability</category></item></channel></rss>