samedi 31 octobre 2020

Design pattern for slightly changed classes

I have 3 classes. All classes are very similar but their implementation slightly differs.

class StrategyA {
  double do() {
    double d = method1();
    method2();
    return method3(d);
  }
}

class StrategyB {
  double do() {
    double d = method1();
    method2();
    return method4(d);
  }
}

class StrategyC {
  double do() {
    double d = method1();
    method3();
    return method4(d);
  }
}

All classes are very similar, most of the logic is the same, but at the end of implementation all classes have slightly different return method. This is only example with single method, there are much more duplicate logic.

How to reduce this implementation to avoid duplication?

Aucun commentaire:

Enregistrer un commentaire