DEV Community

loading...
Cover image for Code Smell 63 - Feature Envy

Code Smell 63 - Feature Envy

mcsee profile image Maxi Contieri ・1 min read

If your method is jealous and don't trust in delegation you should start to do it.

Problems

  • Coupling

  • Low Reuse

  • Low Testability

  • Bad Responsibilities Assignment

  • Bijection Fault

Solutions

  1. Move method to the appropriate class.

Sample Code

Wrong

Right

Detection

Some linters can detect a sequential pattern of collaborations with another object.

Tags

  • Coupling

Conclusion

  • We should assign responsibilities according to real object mappers and avoid abusing other objects protocol.

Relations

More info

Refactoring Guru

C2 Wiki

Wikipedia

Credits

Photo by Hisu lee on Unsplash


We argue that design practices which take a data-driven approach fail to maximize encapsulation because they focus too quickly on the implementation of objects. We propose an alternative object-oriented design method which takes a responsibility-driven approach.

Rebecca Wirfs-Brock

Discussion (2)

pic
Editor guide
Collapse
darkwiiplayer profile image
DarkWiiPlayer

Shouldn't it be the address that does the printing?

Collapse
mcsee profile image
Maxi Contieri Author

It might be another envy, but it is clearly a chance