Will using composition help me avoid large, painful refactors if I change the composition of my components?
If I have an object that inherits, I might say:
Object.Func() // Method implemented by base class.
If I have an object that uses composition, I might say:
ObjectA.ObjectB.Funct() // Using method of Object B.
There are dependencies in both cases. Composition simply changes the way the dependencies are distributed across a set of objects.
* Inheritance is getting something from you parents.
* Composition is getting something from your children.
Both are valuable strategies in systems design. It seems to me that your apparent dislike of inheritance is motivated by the fact that it's currently trendy to dislike inheritance, rather than having any rational / well-reasoned technical motivation.
I don't think you've really read and understood the notion of function composition. All you're talking about here is having objects as properties of other objects - that is not function composition.
I'm not asking about function composition, I'm asking if there is any basis for disliking inheritance other than the fact that it is currently trendy to do so.
The article you are commenting on is about avoiding mixins in React components. It is not a general statement saying “Always use anything called ‘composition’ over anything called ‘inheritance’”.
We found that inheritance doesn’t work well for React components. And we found that composing React components with React’s composition model (which has very little to do with object composition) worked well for us.
Nowhere do we claim that object composition is better than object inheritance, or something else generic like this.
(Sorry if you didn’t interpret it this way. I just want to make it clear for future readers that this branch of discussion is not related to the contents of the article.)
I wouldn't consider 1995 current. And it's gone way beyond "trendy".
EDIT: Also, what you've mentioned there is not composition - it is objects that have other objects as properties. Composition basically involves wrapping and forwarding, whether it's function or object composition.
If I have an object that inherits, I might say:
Object.Func() // Method implemented by base class.
If I have an object that uses composition, I might say:
ObjectA.ObjectB.Funct() // Using method of Object B.
There are dependencies in both cases. Composition simply changes the way the dependencies are distributed across a set of objects.
* Inheritance is getting something from you parents.
* Composition is getting something from your children.
Both are valuable strategies in systems design. It seems to me that your apparent dislike of inheritance is motivated by the fact that it's currently trendy to dislike inheritance, rather than having any rational / well-reasoned technical motivation.