Code Smell 55 - Object Orgy

Subscribe to my newsletter and never miss my upcoming articles

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

  1. Couple to interfaces and behavior, never data.

Sample Code

Wrong

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.

Sonny Alves Dias's photo

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.

Maxi Contieri's photo

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

Bader Alharbi's photo

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 😇

Bader Alharbi's photo

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 :)