"Every time you see duplication in the code, it represents a missed opportunity for abstraction." Duplication should be turned into another function or another class. Additionally, switch cases and if-else chains can represent similar ideas which should be replaced with polymorphism (slightly different classes inheriting from the same parent type)"
void a() { doThing1; doThing2; anotherThing1; anotherThing2; } void b() { doThing3; doThing4; anotherThing1; anotherThing2; }
Could instead be
void a() { doThing1; doThing2; doAnotherThing(); } void b() { doThing3; doThing4; doAnotherThing(); } void doAnotherThing() { anotherThing1; anotherThing2; }
In terms of switch cases/if-else:
void internalClassFunction() { switch (internalClassCondition) { case A: doThingForA() case B: doThingForB() case C: doThingForC() } }
Could instead be:
class Thing { virtual void internalClassFunction() = 0; } ... class ThingTypeA { void internalClassFunction() { doThingForA(); } } class ThingTypeB { void internalClassFunction() { doThingForB(); } } class ThingTypeC { void internalClassFunction() { doThingForC(); } }