Return to site

CODE SMELL: Feature Envy 😋

· code-smell,coding

It happens when a certain function within a module needs to call 📞 functions from other modules too often to complete its functionality. This often happens when functions are spread across 🔀 multiple modules, indicating that the code has low 👎 cohesion.

Why is it bad?

Low cohesion leads to high coupling ⚡ between modules, which makes the code considerably harder to maintain 😫 over the long run. Low cohesion also indicates that the responsibilities of the modules are not well defined 📏📐 and respected.

It may be easy to forget 😵 to call a certain method or to call methods in the incorrect order, leading to many hard-to-find and fix bugs 🪲.

How to fix it?

Move 🖱️ the function that is continuously interacting with another module to that module. More generally, consider improving the design of the system ⚙️ by better setting the boundaries 🛂 between the domains.

"Put things together that change together".