Code Smell 18 - Static Functions
23 October, 2022
3
3
0
Contributors
TL;DR: Don't use static functions. They are global and utilities. Talk to objects instead.
Problems
•
Coupling
•
Testability
•
Protocol Overloading
•
Cohesion
Solutions
•
Class Single Responsibility Principle is to create instance. Honor it.
•
Delegate method to instance.
•
Create stateless objects. Don't call them helpers.
Examples
•
Static class methods
•
Static attributes
Sample Code
Wrong
Right
Detection
Tags
•
Global
•
Libraries
Conclusion
Relations
More info
Credits
There is no programming problem that can't be solved with one more level of indirection.