Composition Over Inheritance

Great episode. 'Prefer Composition over Inheritance` is something that I hear often but usually neglect to apply it, I guess because my brain is wired with a more ‘inheritance’-like style of thinking. I’ll need to watch this a few more times to help it sink in.

A couple of questions:

  • Are there any situations where traditional inheritance still makes sense? Or is it better to always go with composition to provide for more flexibility as code grows over time?
  • And what about Ruby modules, should they generally treated as a code smell? How do you evaluate whether they are a good choice or not?
2 Likes