Code Smell 40 - DTOs
2 January, 2023
2
2
0
Contributors
Problems
•
Anemic Object
•
Inconsistent Data
•
Duplicated logic
•
Class Polluting
•
Information Hiding
•
Code repeated among mutators, accessors, serializers, parsers
•
Ripple Effect
•
Data integrity
Solutions
1.
Transfer anemic data on arrays
2.
Use real business objects
3.
If we want to transfer partial objects: use proxies or null objects to break the reference graph.
Refactorings
Sample Code
Wrong
Right
Detection
•
Conclusion
Relations
More Info
Credits
The best smells are something that's easy to spot and most of time lead you to really interesting problems. Data classes (classes with all data and no behavior) are good examples of this. You look at them and ask yourself what behavior should be in this class.