Software Design/Minimize the diff between implementations of a strategy
Checklist questions:
- Aren't there any unnecessary code differences between classes that extend the same abstract class (like a strategy)?
Why
edit- Increases structuredness and thus makes easier to spot bugs, especially during code reviews.
Why not
editCommon details between several (but not all) of the classes could be pulled up into another intermediate abstract class to eliminate repetition between the leaf classes. For example, if the class hierarchy looked like this:
Aggregate ├── SumAggregate ├── MinAggregate ├── MaxAggregate └── HistogramAggregate
Factoring out ScalarAggregate
would increase the difference between ScalarAggregate
's subclasses (which now would have less code) and HistogramAggregate
. The latter would then look more unique than before the refactoring.
Aggregate ├── ScalarAggregate │ ├── SumAggregate │ ├── MinAggregate │ └── MaxAggregate └── HistogramAggregate