An object that knows too much or does too much.
TL;DR: Don't take too many responsibilities.
-
Cohesion
-
Coupling
Coupling - The one and only software design problem
-
Split responsibilities.
-
Follow Single Responsibility Principle.
-
Follow The Boy Scout Rule.
- Libraries
class Soldier {
run() {}
fight() {}
driveGeneral() {}
clean() {}
fire() {}
bePromoted() {}
serialize() {}
display() {}
persistOnDatabase() {}
toXML() {}
jsonDecode() {}
// ...
}
class Soldier {
run() {}
fight() {}
clean() {}
}
Linters can count methods and warn against a threshold.
- Cohesive
Libraries were fine in the 60. In Object-Oriented Programming, we will distribute responsibilities among many objects.
- Large Class
Code Smell 34 - Too Many Attributes
Code Smell 202 - God Constant Class
Code Smell 124 - Divergent Change
Photo by Francisco Ghisletti on Unsplash
This article is part of the CodeSmell Series.