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...
- 1. Intro to Design Patterns: Welcome to Design Patterns
- from Head First Design Patterns
- Publisher: O'Reilly Media, Inc.
- Released: October 2004
The trade off between inheritance and reuse of code? Either you reuse with inheritance or you lose the benefit of inheritance.
Share this highlighthttp://www.safaribooksonline.com/a/head-first-design/19588/