volume_mute

Refactoring 'Bad Smells'

publish date2026/06/24 21:27:37.560580 UTC

volume_mute

Match each refactoring 'bad smell' to its correct description.

To complete the line match

  1. Click on an item in the first group
  2. Click on the match in the second group

To delete a match, double click on a line

Bad smell

Data clumping
Duplicate code
Long methods
Switch (case) statements
Speculative generality

Description

Generality is included in a program in case it is needed in the future, but can usually simply be removed
Statements scattered around a program that depend on a value's type, often replaceable with polymorphism
The same group of data items reoccurs in several places and could be replaced with an encapsulating object
A method that is too long and should be redesigned as several shorter methods
The same or similar code appears in multiple places and could be extracted into a single reusable method

Correct Answer

(1) Duplicate code,The same or similar code appears in multiple places and could be extracted into a single reusable method
(2) Long methods,A method that is too long and should be redesigned as several shorter methods
(3) Switch (case) statements,Statements scattered around a program that depend on a value's type, often replaceable with polymorphism
(4) Data clumping,The same group of data items reoccurs in several places and could be replaced with an encapsulating object
(5) Speculative generality,Generality is included in a program in case it is needed in the future, but can usually simply be removed

Explanation

Common 'bad smells' that motivate refactoring include: duplicate code (extractable into a shared method); long methods (better split into shorter ones); switch statements (often replaceable with polymorphism in OO languages); data clumping (replaceable with an encapsulating object); and speculative generality (often simply removable).

Reference

Software Engineering, Ian Sommerville, 10th edition


Quizzes you can take where this question appears