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

Why not edit

Common 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

Related edit