Loading ...
Sorry, an error occurred while loading the content.

RE: [XP] Another reason to Extract Method: Cohesion

Expand Messages
  • Tim Haughton (OmniBus - Stanford)
    ... Hi Jeff, ... A truly noble cause. :) ... In another post, I talked about using pain and smell to drive development. If a method s cohesion is low enough to
    Message 1 of 1 , Dec 1, 2003
    • 0 Attachment
      >
      Hi Jeff,

      > Modules (subroutines / functions / procedures / methods) should have
      > High Cohesion and Low Coupling.
      >

      A truly noble cause. :)

      > High Cohesion:
      > All the lines of a method should "work together" to achieve one goal
      > or result. If you look at a method and find that it's doing two or
      > three different things, then it's time to Extract Method. It
      > doesn't matter if the extracted methods are called from multiple
      > locations. If a method has poor Cohesion, then it's time to break
      > it up.

      In another post, I talked about using pain and smell to drive development. If a method's cohesion is low enough to cause me pain, or the method is difficult to test then I'll happily extract a method to make my life easier. What I won't do is preempt the pain and smell.

      I've seen people spend obscene amounts of time chasing high cohesion and low coupling. I've seen people who won't write a concrete class until it has an abstract class to derive from. If you are doing TDD, and are responsive to pain, high cohesion and low coupling are very difficult to avoid.

      Cheers,

      Tim
    Your message has been successfully submitted and would be delivered to recipients shortly.