CS FundamentalsHardProduct-company design interview

Match each code smell with the refactoring that usually fixes it. P: a method takes 9 parameters, several of which always travel together. Q: a switch on employee type is repeated in several methods. R: a 120-line method mixes validation, calculation and formatting. S: a class only forwards every call to another class.

  1. A. P-Introduce Parameter Object, Q-Replace Conditional with Polymorphism, R-Extract Method, S-Remove Middle Man
  2. B. P-Extract Method, Q-Introduce Parameter Object, R-Remove Middle Man, S-Replace Conditional with Polymorphism
  3. C. P-Remove Middle Man, Q-Extract Method, R-Introduce Parameter Object, S-Replace Conditional with Polymorphism
  4. D. P-Introduce Parameter Object, Q-Extract Method, R-Replace Conditional with Polymorphism, S-Remove Middle Man

Correct answer: A. P-Introduce Parameter Object, Q-Replace Conditional with Polymorphism, R-Extract Method, S-Remove Middle Man

Data clumps become a parameter object; repeated type switches become polymorphic subclasses; long methods are split with Extract Method; pure delegators are removed so callers talk to the real object.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic