Coupling and cohesion
Measuring and judging dependencies: the kinds of coupling between modules, afferent and efferent coupling, instability, and the levels of cohesion inside a module, from coincidental to functional.
- 26 cards
- 7 topics
- Free
The outline, topic by topic
Each topic is weighted the way the exam weighs it.
- Concepts
- Questions
- Sort and link
- On the timeline
- The numbers
- Scenarios
- Understand
A few cards from the deck
Coupling: what is it?
Show the answer
The degree of dependence between two modules: the more one knows about the other's inner workings, the more a change to one forces a change to the other.
The aim is a low level: modules that only know each other through a narrow, stable interface can be changed and tested separately.
Which kind of coupling is this call between two modules?
```java
void afficher(String message, boolean enMajuscules) {
if (enMajuscules) { System.out.println(message.toUpperCase()); }
else { System.out.println(message); }
}
afficher("bonjour", true);`- Control coupling: the flag chooses the branch that runs
- Data coupling: only simple values are passed
- Content coupling: the caller modifies the other module's data
- Common coupling: both modules share a variable
Show the answer
Control coupling: the flag chooses the branch that runs
The boolean does not carry data to process: it commands the behaviour of
afficher, so the caller must know its inner workings. Two separate methods or a strategy parameter reduce this coupling.The aim is … coupling between modules and … cohesion inside each one.
Show the answer
The aim is low coupling between modules and high cohesion inside each one.
The two go together: modules that gather what changes together have less need to know each other.
Cohesion: what is it?
Show the answer
The degree to which the elements of a module (methods, fields) serve one responsibility and belong together.
The aim is a high level: a module whose elements have nothing to do with each other is hard to name, understand and reuse.