Code Smell 21 - Anonymous Functions Abusers
30 October, 2022
5
5
0
Contributors
TL;DR: Don't abuse closures and functions. Encapsulate them into objects.
Problems
•
Maintainability
•
Testability
•
Code Reuse
•
Implementation Hiding
•
Debugging
Solutions
1.
Wrap functions/closures
2.
Reify algorithms in method object / Strategy
Sample Code
Wrong
Right
Detection
•
Tags
•
Primitive
•
Abuser
Conclusion
Relations
Credits
Object-oriented programming increases the value of these metrics by managing this complexity. The most effective tool available for dealing with complexity is abstraction. Many types of abstraction can be used, but encapsulation is the main form of abstraction by which complexity is managed in object-oriented programming.