| ▲ | hansvm 6 hours ago | |||||||||||||||||||||||||
"Gluing together in a way that's not inheritance" is useful enough by itself. Most class hierarchies are wrong, and even when they're right people tend to implement th latest and greatest feature by mucking with the hierarchy in a way which generates wrongness, mostly because it's substantially easier, given a hierarchy, to implement the feature that way. Inheritance as a way of sharing code is dangerous. The thing composition does differently is to prevent the effects of the software you're depending on from bleeding further downstream and to make it more explicit which features of the code you're using you actually care about. Inheritance has a place, but IME that place is far from any code I'm going to be shackled to maintaining. It's a sometimes-necessary evil rather than a go-to pattern (or, in some people's books, that would make it a pattern like "go-to"). | ||||||||||||||||||||||||||
| ▲ | tombert 6 hours ago | parent [-] | |||||||||||||||||||||||||
I don't think that it really is a useful enough definition. There are lots of ways to glue things together that aren't inheritance that are very different from each other. I could compose functions together like the Haskell `.`, which does the regular f(g(x)), and I don't think anyone disputes that that is composition, but suppose I have an Erlang-style message passing system between two processes? This is still gluing stuff together in a way that is not inheritance, but it's very different than Haskell's `.`. | ||||||||||||||||||||||||||
| ||||||||||||||||||||||||||