principles:high_cohesion
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
principles:high_cohesion [2012-12-17 22:01] – Constantine's Law christian | principles:high_cohesion [2016-09-03 22:52] – [Class level cohesion] 5.12.30.152 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== High Cohesion ====== | + | ====== High Cohesion |
===== Variants and Alternative Names ===== | ===== Variants and Alternative Names ===== | ||
Line 6: | Line 6: | ||
===== Context ===== | ===== Context ===== | ||
/* fill in contexts here: */ | /* fill in contexts here: */ | ||
- | * [[contexts: | + | * [[contexts: |
+ | * [[contexts: | ||
+ | * [[contexts: | ||
- | ===== Definition | + | ===== Principle Statement |
[[glossary: | [[glossary: | ||
Line 19: | Line 21: | ||
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: FIXME add explanation of cohesion types | 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: FIXME add explanation of cohesion types | ||
+ | |||
===== Rationale ===== | ===== 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. | 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. | ||
+ | |||
+ | |||
+ | ===== Strategies ===== | ||
+ | |||
+ | * Divide one large module into several smaller but more cohesive ones | ||
+ | |||
+ | ===== Caveats ===== | ||
+ | |||
+ | See section [[#contrary principles]]. | ||
===== Origin ===== | ===== Origin ===== | ||
- | /* the *primary* source */ | ||
+ | W. P. Stevens, | ||
===== Evidence ===== | ===== Evidence ===== | ||
Line 32: | Line 44: | ||
/ | / | ||
- | * [[wiki: | + | * [[wiki: |
- | * [[wiki: | + | * [[wiki: |
/ | / | ||
Line 44: | Line 56: | ||
==== Specializations ==== | ==== Specializations ==== | ||
- | * [[principles:Information Expert]]: Adhering to information expert means that a module only has responsibilities which belong together. So this increases cohesion. | + | * [[Constantine' |
- | * [[principles: | + | * [[Single Responsibility Principle]] (SRP): SRP is a stronger version of HC. |
+ | * [[Interface Segregation Principle]] (ISP): ISP is the application of HC to interfaces. | ||
==== Contrary Principles ==== | ==== Contrary Principles ==== | ||
- | * [[principles: | + | * [[More Is More Complex]] (MIMC): Making a module highly cohesive often results in additional modules. |
+ | * [[Model Principle]] (MP): Adhering to HC sometimes means to split up a class into several smaller ones which might correspond to the model less well. | ||
+ | * [[Low Coupling]] (LC): A system consisting | ||
==== Complementary Principles ==== | ==== Complementary Principles ==== | ||
- | * [[principles:Low Coupling]] | + | * [[Tell don't Ask/ |
- | * [[principles: | + | * [[Encapsulate the Concept that Varies]] (ECV): Adhering to HC often results in modules to be split up into several more cohesive ones. ECV gives further advice on how to do that. |
==== Principle Collections ==== | ==== Principle Collections ==== | ||
Line 62: | Line 78: | ||
- | ===== Example | + | ===== Examples |
Line 70: | Line 86: | ||
/ | / | ||
/ | / | ||
+ | |||
+ | ==== 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 ===== | ===== Further Reading ===== | ||
- | * Albert Endres and Dieter Rombach: //A Handbook of Software and Systems Engineering// | + | * Albert Endres and Dieter Rombach: //[[resources: |
+ | * [[wp> | ||
+ | * [[wiki> | ||
+ | * {{page> | ||
+ | |||
+ | ===== Discussion ===== | ||
+ | Discuss this wiki article and the principle on the corresponding [[talk: |
principles/high_cohesion.txt · Last modified: 2021-10-18 21:36 by christian