Code Smell 55 - Object Orgy
If you see your objects as data holders you will violate their encapsulation, but you shouldn't, as in real life, you should always ask for consent.
Problems
Information Hiding Violation
Encapsulation Violation
Coupling
Solutions
- Couple to interfaces and behavior, never data.
Sample Code
Wrong
Right
Detection
You can set your linters to warn you for public attributes, setters and getters usage and discourage them.
Tags
- Coupling
Conclusion
If your classes are polluted with setters, getters and public methods you will certainly have ways to couple to their accidental implementation.
Also Known as
- Inappropriate intimacy
Relations
More info
Credits
Picture by Nicolas Poussin
A data structure is just a stupid programming language.
Bill Gosper
This article is part of the CodeSmell Series.
CTO of Pixelmatic
I am wondering until where you are going to go... Already 55 code smells. Really good series I recommend to any software engineer working with OOP. Quick question, do you use all of them? Some can be detected by linters some not how do you deal with those? Some are also obvious with the experience so maybe the final list is not that big.
Thank you
I try to follow uncle bob's boy scout rule
If I see some of these smells I try to refactor them.
i directly avoid many of them . But I work in a huge codebase with a lot of people so the code has lots of layers
Computing to crack biology
Amazing Content bro! I love code smell content, I read them all, I'm not a hardcore (biology background self-taught programmer) but I had no trouble following up, I wish I can write like you! I'm officially a fan 😇
Also, I have not made my first blog yet, but if do one day, I would like to have your blessing to imitate your style :)
Comments (4)