Monday, October 23, 2006

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() {}




Note: This post was originally posted on my blog at

No comments: