<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://msmvps.com/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>Fundamentals of OOD Part 3: Method Cohesion</title><link>http://msmvps.com/blogs/peterritchie/archive/2008/06/10/fundamentals-of-ood-part-3-method-cohesion.aspx</link><description>Single Responsibility Principle (SRP) helps us write more cohesive types and methods. Cohesion is the relatedness of the members of a type to each other and the relatedness parts of a method&amp;#39;s code to other parts. Method cohesion Often times a method</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><item><title>re: Fundamentals of OOD Part 3: Method Cohesion</title><link>http://msmvps.com/blogs/peterritchie/archive/2008/06/10/fundamentals-of-ood-part-3-method-cohesion.aspx#1638271</link><pubDate>Fri, 27 Jun 2008 07:25:55 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1638271</guid><dc:creator>JJ</dc:creator><description>&lt;p&gt;Great blog, very informative!&lt;/p&gt;
&lt;p&gt;I have a question, what are your thoughts on creating an extension method of PerformOperation? This way PerformOperation is not &amp;#39;physically&amp;#39; part of the Operation-derived class, however, one can still invoke it as if.&lt;/p&gt;
&lt;p&gt;One may wonder, however, what the added value would be over just calling Execute on the object.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1638271" width="1" height="1"&gt;</description></item><item><title>re: Fundamentals of OOD Part 3: Method Cohesion</title><link>http://msmvps.com/blogs/peterritchie/archive/2008/06/10/fundamentals-of-ood-part-3-method-cohesion.aspx#1634967</link><pubDate>Sat, 14 Jun 2008 11:44:22 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1634967</guid><dc:creator>PeterRitchie</dc:creator><description>&lt;p&gt;Felipe, my example is very simple. &amp;nbsp;I a real-world case after you perform this change you may actually want to refactor to what you've suggested. &amp;nbsp;It depends on the project and depends on what you want to accomplish. &amp;nbsp;&amp;quot;PerformOperation&amp;quot; isn't very descriptive and isn't very intention-revealing; so, yes, simply calling the Operation-derived class directly may be a valid refactoring. &amp;nbsp;If &amp;quot;PerformOperation&amp;quot; has a more descriptive name--being more intention revealing--then refactoring to just calling the Operation-derived class directly would likely make the code less clear.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1634967" width="1" height="1"&gt;</description></item><item><title>re: Fundamentals of OOD Part 3: Method Cohesion</title><link>http://msmvps.com/blogs/peterritchie/archive/2008/06/10/fundamentals-of-ood-part-3-method-cohesion.aspx#1634802</link><pubDate>Fri, 13 Jun 2008 19:44:51 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1634802</guid><dc:creator>Felipe Fujiy Pessoto</dc:creator><description>&lt;p&gt;Peter, answer my question please&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1634802" width="1" height="1"&gt;</description></item><item><title>re: Fundamentals of OOD Part 3: Method Cohesion</title><link>http://msmvps.com/blogs/peterritchie/archive/2008/06/10/fundamentals-of-ood-part-3-method-cohesion.aspx#1634750</link><pubDate>Fri, 13 Jun 2008 13:42:56 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1634750</guid><dc:creator>PeterRitchie</dc:creator><description>&lt;p&gt;Assam, I'm glad they help.&lt;/p&gt;
&lt;p&gt;The factory pattern implements no business logic (the policy) the Strategy pattern does implement business logic. &amp;nbsp;You could use a factory pattern to decouple the code that uses an Operation implementation from the various implementations; but then you'd be using Factory and Strategy.&lt;/p&gt;
&lt;p&gt;No, the Factory pattern and the Strategy pattern are not interchangeable. &amp;nbsp;Factory merely abstracts the creation of objects. &amp;nbsp;Strategy encapsulates and abstracts policy.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1634750" width="1" height="1"&gt;</description></item><item><title>re: Fundamentals of OOD Part 3: Method Cohesion</title><link>http://msmvps.com/blogs/peterritchie/archive/2008/06/10/fundamentals-of-ood-part-3-method-cohesion.aspx#1634722</link><pubDate>Fri, 13 Jun 2008 12:15:54 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1634722</guid><dc:creator>Assam</dc:creator><description>&lt;p&gt;Hello, your blogs always make a dumb like me to understand things in such a simpler way. So i say thanks to you. After reading this i actually questioned my senior and asked him what pattern would he use in the scenario you presented. He said he would use factory pattern(though i dont agree). His stance was that Strategy and Factory patterns are quite similar so they can be use interchangeably. My question is can factory pattern be used for the problem you presented.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1634722" width="1" height="1"&gt;</description></item><item><title>re: Fundamentals of OOD Part 3: Method Cohesion</title><link>http://msmvps.com/blogs/peterritchie/archive/2008/06/10/fundamentals-of-ood-part-3-method-cohesion.aspx#1634236</link><pubDate>Thu, 12 Jun 2008 01:56:45 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1634236</guid><dc:creator>Felipe Fujiy Pessoto</dc:creator><description>&lt;p&gt;I have a question. In the end, which serves the PerformOperation?&lt;/p&gt;
&lt;p&gt;I can just do:&lt;/p&gt;
&lt;p&gt;Operation operation = new AndOperation();&lt;/p&gt;
&lt;p&gt;IList&amp;lt;int&amp;gt; = operation.Execute(left, right);&lt;/p&gt;
&lt;p&gt;Sorry for bad english&lt;/p&gt;
&lt;p&gt;Ty.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1634236" width="1" height="1"&gt;</description></item><item><title>re: Fundamentals of OOD Part 3: Method Cohesion</title><link>http://msmvps.com/blogs/peterritchie/archive/2008/06/10/fundamentals-of-ood-part-3-method-cohesion.aspx#1633999</link><pubDate>Wed, 11 Jun 2008 14:05:20 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1633999</guid><dc:creator>PeterRitchie</dc:creator><description>&lt;p&gt;Steve, yes, Intersection and And are the same (which makes the fact that my Innersection code and my And code are different all the more stranger :-).&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1633999" width="1" height="1"&gt;</description></item><item><title>re: Fundamentals of OOD Part 3: Method Cohesion</title><link>http://msmvps.com/blogs/peterritchie/archive/2008/06/10/fundamentals-of-ood-part-3-method-cohesion.aspx#1633913</link><pubDate>Wed, 11 Jun 2008 09:33:19 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1633913</guid><dc:creator>Steve</dc:creator><description>&lt;p&gt;But that means Intersection and And are the same :)&lt;/p&gt;
&lt;p&gt;But that wasn&amp;#39;t the point I know :D&lt;/p&gt;
&lt;p&gt;Great article, I just wish more developers would know this :(&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1633913" width="1" height="1"&gt;</description></item><item><title>re: Fundamentals of OOD Part 3: Method Cohesion</title><link>http://msmvps.com/blogs/peterritchie/archive/2008/06/10/fundamentals-of-ood-part-3-method-cohesion.aspx#1633800</link><pubDate>Wed, 11 Jun 2008 01:58:58 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1633800</guid><dc:creator>PeterRitchie</dc:creator><description>&lt;p&gt;Eyal-Shilony. &amp;nbsp;Good question. &amp;nbsp;I chose an abstract class over an interface because I think it's more clear in this circumstance. &amp;nbsp;It's more clear that the strategy implementation is expected to do only one thing.&lt;/p&gt;
&lt;p&gt;I this case it does only one thing, we don't use other classes that might do other things so rather than over-design we use the simplest thing that fulfills our requirements. &amp;nbsp;Should you want to have a class that can fulfill more than one interface contract then use of interface might be more appropriate. &amp;nbsp;I generally think that implementing more than one interface likely means the class is violating SRP. In this case we're more likely to implement a class that has a single responsibility because it can only have one base (the abstract Operation).&lt;/p&gt;
&lt;p&gt;But, yes, interface could have just as easily been used.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1633800" width="1" height="1"&gt;</description></item><item><title>re: Fundamentals of OOD Part 3: Method Cohesion</title><link>http://msmvps.com/blogs/peterritchie/archive/2008/06/10/fundamentals-of-ood-part-3-method-cohesion.aspx#1633796</link><pubDate>Wed, 11 Jun 2008 01:53:38 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1633796</guid><dc:creator>PeterRitchie</dc:creator><description>&lt;p&gt;Steve, good question. &amp;nbsp;You're obviously paying attention :-).&lt;/p&gt;
&lt;p&gt;Yes, you don't need that second loop, I'll remove it.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1633796" width="1" height="1"&gt;</description></item><item><title>re: Fundamentals of OOD Part 3: Method Cohesion</title><link>http://msmvps.com/blogs/peterritchie/archive/2008/06/10/fundamentals-of-ood-part-3-method-cohesion.aspx#1633783</link><pubDate>Wed, 11 Jun 2008 00:55:36 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1633783</guid><dc:creator>Eyal-Shilony</dc:creator><description>&lt;p&gt;Hello, first I would like to say that you inspire me, your blogs are enjoyable. :)&lt;/p&gt;
&lt;p&gt;The &amp;quot;Operation&amp;quot; type contain no implementations, so I wonder for the reason you used abstract class over an interface, can you enlighten me with reason ? or was it just for the example ? (silly as it may sound).&lt;/p&gt;
&lt;p&gt;Thank you for your time, regards!&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1633783" width="1" height="1"&gt;</description></item><item><title>re: Fundamentals of OOD Part 3: Method Cohesion</title><link>http://msmvps.com/blogs/peterritchie/archive/2008/06/10/fundamentals-of-ood-part-3-method-cohesion.aspx#1633738</link><pubDate>Tue, 10 Jun 2008 22:39:33 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1633738</guid><dc:creator>Steve</dc:creator><description>&lt;p&gt;Great post, but for the AndOperation, isn&amp;#39;t the second foreach unnecessary? Since it has to be in BOTH it&amp;#39;s enough to just check one collection, in other words, there will never be an item that will be added in the second foreach :)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1633738" width="1" height="1"&gt;</description></item><item><title>Fundamentals of OOD, method cohesion</title><link>http://msmvps.com/blogs/peterritchie/archive/2008/06/10/fundamentals-of-ood-part-3-method-cohesion.aspx#1633694</link><pubDate>Tue, 10 Jun 2008 19:58:18 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1633694</guid><dc:creator>DotNetKicks.com</dc:creator><description>&lt;p&gt;You&amp;#39;ve been kicked (a good thing) - Trackback from DotNetKicks.com&lt;/p&gt;
&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1633694" width="1" height="1"&gt;</description></item></channel></rss>