3 ms·
This article seems to be criticizing _automatic delegation_, not _composition_. Delegation is not necessary for every (or even most) instance of composition. Be
by djur 9y ago
This article seems to be criticizing _automatic delegation_, not _composition_. Delegation is not necessary for every (or even most) instance of composition. Beyond that, languages provide more narrowly-tailored forms of delegation than "forward every method that the underlying object supports".
Furthermore, the criticism of inheritance that the article sets up isn't the one that "composition over inheritance" is meant to address. Languages like Java with access modifiers (public/private/protected) don't have the accidental namespace collision issue the writer demonstrates, and yet "composition over inheritance" is a popular concept in those languages, too. The problem with inheritance is that the Liskov substitution principle is very easy to accidentally violate, and those violations can lead to a brittle and inflexible design over time. (See https://en.wikipedia.org/wiki/Circle-ellipse_problem https://en.wikipedia.org/wiki/Circle-ellipse_problem)
Finally, I don't understand the relevance of the "sororicide" metaphor, nor does the article describe anything identifiable as an antipattern.