<?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  : Design Principles</title><link>http://weblogs.asp.net/arturtrosin/archive/tags/Design+Principles/default.aspx</link><description>Tags: Design Principles</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><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>2</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/Software+Architecture/default.aspx">Software Architecture</category><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/General+Software+Development/default.aspx">General Software Development</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/Design+Principles/default.aspx">Design Principles</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>6</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/Code+Readability/default.aspx">Code Readability</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/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/Patterns/default.aspx">Patterns</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/Design+Principles/default.aspx">Design Principles</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/Software+Architecture/default.aspx">Software Architecture</category><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></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>23</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, ubiquities 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: ubiquities 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;Ubiquities 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/Software+Architecture/default.aspx">Software Architecture</category><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/Patterns/default.aspx">Patterns</category><category domain="http://weblogs.asp.net/arturtrosin/archive/tags/Design+Principles/default.aspx">Design Principles</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>3</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/C_2300_/default.aspx">C#</category><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></item></channel></rss>