ConstructiCat Logo
CodeBust.
Browse section ▾

Feature Envy.

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

##Signs and Symptoms

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

class InvoicePrinter {
  String line(Order order) {
    return order.customer.name + ": " + order.item.sku + " x" + order.item.qty;
  }
}

##Reasons for the Problem

This smell may occur after fields are moved to a data class. If this is the case, you may want to move the operations on data to this class as well.

##Treatment

##Payoff

  • Less code duplication (if the data handling code is put in a central place).

  • Better code organization (methods for handling data are next to the actual data).