Code Smell 14 - God Objects
Don't take too many responsibilities.
13 October, 2022
2
2
0
Contributors
An object that knows too much or does too much.
TL;DR: Don't take too many responsibilities.
Problems
•
Cohesion
•
Coupling
Solutions
•
Split responsibilities.
•
Follow Single Responsibility Principle.
•
Follow The Boy Scout Rule.
Examples
•
Libraries
Sample Code
Wrong
Right
Detection
Linters can count methods and warn against a threshold.
Exceptions
Tags
•
Cohesive
Conclusion
Libraries were fine in the 60. In Object-Oriented Programming, we will distribute responsibilities among many objects.
Also Known as
•
Large Class
Relations
More info
Credits
Photo by Francisco Ghisletti on Unsplash
This article is part of the CodeSmell Series.
cleancode
codesmell