8th Light: Day 100

20 May 2016 . 8thlight . Comments #apprenticeship #8thlight #software #code-smells

Code smells: Feature envy

A method accesses the data of another object more than its own data. - sourcemaking.com

Objects are a techique to package data with the processes that use the data. Feature envy is a smell when a method or function is using data from another object or namespace more than in itself. If this happens, it’s probably a good idea to move the method to the other class.

Ways to fix feature envy:

Benefits:

  • Less duplication
  • Better organization
  • Data and processes coupled together reside in the same space
  • Less spaghetti code