Return to site

CODE SMELL: Feature Envy ๐Ÿ˜‹

November 26, 2022

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".