Design Problems
-
Exchanging Algorithms at Run-Time
-
How can a class be configured with an algorithm at run-time
instead of implementing an algorithm directly?
-
How can an algorithm be selected and exchanged at run-time?
-
Flexible Alternative to Subclassing
-
How can a flexible alternative be provided to subclassing
for changing an algorithm at compile-time?
Refactoring Problems
[BGI]
-
Inflexible Code
-
How can hard-wired algorithms
(compile-time implementation dependencies)
be refactored?
-
Duplicated Code
-
How can algorithms that are duplicated in multiple places
be refactored?
-
How can many related classes
that differ only in their algorithms
be replaced
by a common class that is configured
with one of many algorithms?
-
Complicated Code
-
How can conditional statements
that switch between different
algorithms
be eliminated?
Replace Conditional Logic with Strategy (129)
[JK05]
Background Information
-
Refactoring and "Bad Smells in Code"
[MF99]
[JK05]
-
Code smells
are certain structures in the code that "smell bad" and
indicate problems that can be solved by a refactoring.
-
The most common code smells are:
complicated code
(including complicated/growing conditional code),
duplicated code,
inflexible code
(that must be changed whenever requirements change), and
unclear code
(that doesn't clearly communicate its intent).