Hacker News new | ask | show | jobs
by lenticular 2601 days ago
>Whereas with composition, you now need to manually implement all 20+ methods in the interface, just to make the pass-through call. This adds a tremendous amount of boilerplate to the code.

Inheritance is not necessary for this. The traditional way of achieving this in functional languages is to use a closure to return an object/record. Instead of brittle inheritance, just pass this object to another function that returns an object modified however you want it. Objects can be combined too, achieving the same goal as multiple inheritance, but less dangerous. Simple, easy, succinct, composable.

1 comments

I agree that inheritance is not necessary for this, if languages provided better built-in support for the composition pattern. I was referring to the downsides of using composition in today's "enterprise" languages like Java.