0

"...shouldn't we always turn inheritance from a concrete class into inheritance from an abstract class (using the Employee classes as a model)? The answer would appear to be yes, except that another heuristic gets in our way." Heuristic 3.7 Eliminate irrelevant classes from your design.

Can anyone explain why all classes except leaves should be abstract ? And the realtionship of heuristic 3.7 as an exception or "counter-heuristic".

If I have an Employee generic class with different specializations, I see no problem making possible to instantiate Employee neither Person nor Human nor LivingBeing

Asier Naiz
  • 141
  • 6
  • A easy way to look at this is to think in terms of generalisation instead of specialisation. That is, you generalise leaf classes into abstract classes. These base classes are relevant because they represent the supersets of their subordinate classes, but they remain abstract because they are not instantiated. I believe the teaching of inheritance in OOP (as opposed to OOD) has corrupted the idea of generalisation into specialisation whereas the former is simpler to reason with. – RWRkeSBZ Sep 25 '21 at 15:27
  • See https://stackoverflow.com/questions/16724946/why-derive-from-a-concrete-class-is-a-poor-design – ahoffer Oct 15 '21 at 05:14
  • Does this answer your question? [why derive from a concrete class is a poor design](https://stackoverflow.com/questions/16724946/why-derive-from-a-concrete-class-is-a-poor-design) – ahoffer Oct 15 '21 at 05:15

0 Answers0