CS FundamentalsHardWipro · Cognizant technical pattern

A method in class Invoice spends most of its code reading fields of a Customer object (name, address, discount tier) and barely uses Invoice’s own data. Which code smell is this, and what is the usual refactoring?

  1. A. God class — split Invoice into many classes
  2. B. Feature envy — move the method (or that part of it) into Customer
  3. C. Shotgun surgery — merge Invoice and Customer
  4. D. Primitive obsession — replace the fields with strings

Correct answer: B. Feature envy — move the method (or that part of it) into Customer

A method more interested in another class’s data than its own shows feature envy; moving it next to the data improves cohesion and reduces coupling. Shotgun surgery is when one change needs edits in many classes; a god class does too much overall.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic