Alternative Classes with Different Interfaces
Symptoms
Causes
People create similar code to handle a similar situation, but don't realize the other code exists.
What to Do
Harmonize classes so that you can eliminate one of them.
Rename Method to make method names similar. Move Method, Add Parameter, and Parameterize Method to make protocols (method signatures and approach) similar. If the two classes are similar but not identical, use Extract Superclass once you have them reasonably well harmonized. Remove the extra class if possible.
Payoff
Reduces duplication. May also reduce size. May improve communication (by removing ambiguity about which approach to use).
Contraindications
Sometimes the two classes can't be changed (e.g., if both are in different libraries). Each library may have its own vision for the same concept, but you may be left with no good way to unify them.
|