O'Reilly logo
  • Ahmed Elgendy thinks this is interesting:

What would you do if you were Joe?

We know that not all of the subclasses should have flying or quacking behavior, so inheritance isn’t the right answer. But while having the subclasses implement Flyable and/or Quackable solves part of the problem (no inappropriately flying rubber ducks), it completely destroys code reuse for those behaviors, so it just creates a different maintenance nightmare. And of course there might be more than one kind of flying behavior even among the ducks that do fly...


Cover of Head First Design Patterns


The trade off between inheritance and reuse of code? Either you reuse with inheritance or you lose the benefit of inheritance.