Code Smell 34 - Too Many Attributes
Maxi Contieri
Posted on November 25, 2020
A class defines objects with lots of attributes.
Problems
Low Cohesion
Coupling
Maintainability
Readability
Solutions
- Find methods related to attributes.
- Cluster these methods.
- Break the object related to those clusters.
- Find real objects related to this new objects and replace existing references.
Examples
DTOs
Denormalized table rows
Sample Code
Wrong
Right
Detection
Most linters warn when you declare too many attributes. Setting a good warning threshold should be easy.
Tags
- primitive
Conclusion
Bloated objects know too much and are very difficult to change due to cohesion.
Developers change these objects a lot, so they bring merge conflicts and are a common problems source.
Relations
Code Smell 10β-βToo Many Arguments
Maxi Contieri γ» Oct 29 '20
#codenewbie
#beginners
#100daysofcode
#oop
Credits
So much complexity in software comes from trying to make one thing do two things.
Ryan Singer
π πͺ π
π©
Maxi Contieri
Posted on November 25, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.