DEV Community

Discussion on: Why composition is superior to inheritance as a way of sharing code

Collapse
 
ruidfigueiredo profile image
Rui Figueiredo

Hi James,

The article starts by distinguishing implementation inheritance from interface inheritance. And specifically the use of implementation inheritance as a way to share code (this is where you have a base class and you derive from it to access its methods, no polymorphism is used here).

If you are talking about inheritance being essential in presentation specifically to take advantage of polymorphism them I agree, but that was not the point of the article.

Collapse
 
jim_ej profile image
James Ellis-Jones

Hi Rui

Thanks for your response. My apologies that I misunderstood your limitation of the point you were making. I think we can then agree that in cases where you need polymorphism together with sharing code, inheritance has it's uses, but where polymorphism is not relevant, composition is preferable.