Re:React: Mixins Considered Harmful
by danabramov on Thursday July 14, 2016 @08:37AM
(#12093189)
When people say “composition” they refer to different things. You are referring to object composition.
In React, “composition” means has a very specific meaning: it’s putting components into components. It has very little to do with object composition because in React component instances almost never “talk” to each other. They don’t call methods on each other.
React component model is much closer to functional composition which doesn’t suffer from the drawbacks you describe.
Composition has the exact same problem in this respect.
* Object A
* Object B
* Object C
Object C is composed of Object A and Object B.Now go and write code that has instances of Object C. Can you remove Object A without side effects? The amount of pain you experience from removing Object A from Object C isn't related to composition or inheritance. It's related to how often you use a particular object. Furthermore, if you're a library author, pain and inflexibility can arise from how API customers react to breaking changes ( badly ). In this case, it really doesn't matter whether or not you're using inheritance or composition.
It amazes me how many programmers cannot seem to understand this.