Friday, September 21, 2007

High cohesion












[Time: 4 mins]


  • Stuff that goes together, stays together
  • Easy to discover relevant code
  • Levels of cohesion
    • packages
    • classes
    • methods
So in very simple words, cohesion is keeping related stuff together so we can find what we want without too much difficulty.















Example 1:

public class Student {

//cohesive methods

public void registerForCourse() {}

public void deregisterFromCourse() {}

viewTranscripts() {}

//methods below are not in synch with the responsibilities of the Student class

//hence cohesion is broken

submit grades() {}

submitCourseSchedule() {}



}




Java2html





Resources:


Note: This text was originally posted on my earlier blog at http://www.adaptivelearningonline.net

No comments: