Abstract Class for Providing Flexible Behavior for Related Classes

If there is a common interface for all concrete implmentations of your abstract class, it means you are just using Inheritance to define/change certain behaviour of the class.

classDiagram iCar <|-- AbstractCar AbstractCar <|-- GoCart AbstractCar <|-- FastCar

You should rather prefer Composition over Inheritance.

Just turn your abstract class into a concrete implementation and inject the "behaviour" which you are trying to change from outside using Strategy Pattern.

classDiagram iCar <-- Car class Car{ + iMotor motor } iMotor <-- FastMotor iMotor <-- GoCartMotor

References

Nigel Thorne's answer to How to Unit Test Abstract Classes?


Backlinks