3 ms·
Not really, at all. Order the traits differently and you can get different behavior. Inherit one subtrait vs another and you can get different behavior. You
by jbooth 11y ago
Not really, at all. Order the traits differently and you can get different behavior. Inherit one subtrait vs another and you can get different behavior. You can reason about all of this, but I'm not that smart, so I prefer composition.
Composition locks away the behavior you want so that you know exactly what you're getting.
- twic 11y agoI don't get it. If you're decorating, then ordering the decorators differently gets you different behaviour. It's exactly the same. Indeed, you could write a straightforward mechanical method to convert any trait stacking into a decoration.
- jbooth 11y agoYeah -- I'm arguing for composition because it's harder to screw up, at the cost of being less pretty. The manner and order in which composed objects are delegated to is crystal clear if you're wiring them yourself (or with your IDE). I've seen some messy, confusing code involving traits and just slapping 'with Thingy' 10 times in a row. The phrase 'emergent behavior' is how I would best describe it.