DEV Community

Cover image for Code Smell 31 - Accidental Methods on Business Objects
Maxi Contieri ⭐⭐⭐
Maxi Contieri ⭐⭐⭐

Posted on • Updated on • Originally published at


Code Smell 31 - Accidental Methods on Business Objects

Adding persistence, serialization, displaying, importing, exporting code to an object bloats its protocol and brings coupling.


  • Readability

  • Coupling

  • Maintainability


  1. Keep your objects clean.

  2. Decouple business objects.

  3. Separate accidental concerns: Move Persistence, Formatting, Serialization to special objects.

  4. Keep essential protocol using bijection.


  • Persistence

  • Identifiers

  • Serialization

  • Formatting

Sample Code




It is difficult (but not impossible) to create linting rules based on naming and hinting for suspect names.


  • Some frameworks force us to inject dirty code in our objects. (For example identifiers).

We should try to use better languages/frameworks.


  • Declarative


We are very used to see business objects polluted. This is normal. We need to reflect on the consequences and coupling from these designs.


Photo by Robert Bye on Unsplash

Simple things should be simple, complex things should be possible.

Alan Kay

Top comments (0)

50 CLI Tools You Can't Live Without

The top 50 must-have CLI tools, including some scripts to help you automate the installation and updating of these tools on various systems/distros.