Cohesion
- Tags
- comp-sci
A design metric that [see page 29, measures] how well a component fits together, that is whether everything in a bundle of code (referred to as a component) needs to be there.
In general a component should be highly cohesive, implementing a single logical entity or function, and changes (when required) should be localised to a single cohesive component. Components can be classes, modules or higher level groupings of code.
Cohesion | Strength | Description |
---|---|---|
Coincidental Cohesion | Weak | Parts of a component are simply bundled together |
Logical Association | Weak | Components performing similar functions are grouped |
Temporal Cohesion | Weak | Components activated at the same time are grouped |
Communicational Cohesion | Medium | All elements of a component operate on the same input or produce the same output |
Sequential Cohesion | Medium | The output for one part of a component is the input to another part |
Functional Cohesion | Strong | Each part of a component is necessary for the execution of a single function |
Object Cohesion | Strong | Each operation provides functionality which allows object attributes to be modified or inspected |