0

I remembered that I read once in a book that teaches

try to use composition as far as you could. I forgot the reasons now, anyone could give the hint?

Adam Lee
  • 24,710
  • 51
  • 156
  • 236
  • You can argue this (as is the case with many other rules), but inheritance is rigid and finalized at compile time, also inheritance breaks encapsulation. – NoChance Feb 19 '15 at 01:29
  • I think you meant composition rather than containment. – plalx Feb 19 '15 at 04:54
  • 1
    possible duplicate of [Prefer composition over inheritance?](http://stackoverflow.com/questions/49002/prefer-composition-over-inheritance) – plalx Feb 19 '15 at 04:55

2 Answers2

1

I had been confused same as you until I found this explanation: Inheritance is Bad: Code Reuse Great example where author explain inheritance based on example typically used to show why inheritance is "great".

cslysy
  • 810
  • 7
  • 11
-1

Favor 'object composition' over 'class inheritance'. (Gang of Four 1995:20) Read the book

zzfima
  • 1,528
  • 1
  • 14
  • 21