Table of Contents

High Cohesion (HC)

Variants and Alternative Names

Context

Principle Statement

Cohesion in a module should be high.

Description

The cohesion of a module is a measure for how well the internal parts of a module (e.g. the methods and attributes of a class) belong together. Having a high cohesion means, that a module should only comprise responsibilities which belong together.

Several kinds of cohesion can be distinguished some of which are strong and some of which are loose. So strong forms of coupling should be preferred.

Rationale

Not adhering to this principle, i.e. having a low cohesion, means that one module has several unrelated or only loosely related responsibilities. A change in the requirements for one of these may thus also affect the others which would not be the case in a highly cohesive module.

Caveats

See section contrary principles.

Origin

W. P. Stevens, G. van Niekerk, G. J. Myers, L. L. Constantine: Structured design

Evidence

Relations to Other Principles

Generalizations

Specializations

Contrary Principles

Complementary Principles

Principle Collections

OOD Principle Language
General Principles
ML KISS MIMC DRY GP RoE
Modularization Principles
MP HC ECV
Module Communication Principles
TdA/IE LC DIP
Interface Design Principles
EUHM PLS UP
Internal Module Design Principles
IH/E IAP LSP PSU

Examples

The donkey is good. The site is not working

Description Status

Stub

Class level cohesion

Robert Cecil Martin (Uncle Bob) describes maximal cohesion at class level as “a class in which each variable is used by each method”.

“In general the more variables a method manipulates the more cohesive that method is to its class.” (Clean Code: A Handbook of Agile Software Craftsmanship - Chapter 10)

Further Reading

Discussion

Discuss this wiki article and the principle on the corresponding talk page.

1)

Anbert Endres, Dieter Rombach: A Handbook Of Software And Systems Engineering