DEV Community

Discussion on: What's so bad about inheritance in comparison to composition?

Collapse
 
vonheikemen profile image
Heiker

The thing about inheritance is that you have to be careful when you design the hierarchy of your classes. It might solve an immediate problem that you have but later down the road they can become an obstacle to implement a new feature. I've heard people say that you should only use inheritance when you are absolutely sure you only need a Parent and Child class, that is a hierarchy with just one level.

When you use composition techniques it should be easier to just add new code without worrying about old code.