3 ms·
Can you give an actual example of the difference between composition and delegation? In my definition those two are just two different perspectives on the same
by jkrems 13y ago
Can you give an actual example of the difference between composition and delegation? In my definition those two are just two different perspectives on the same thing.
- _getify 13y agoA super quick, simple illustration of the difference, which comes down to the fact that delegation is differential, whereas composition is complete: https://gist.github.com/getify/9895188 https://gist.github.com/getify/9895188 For a bit more "real world" of a scenario, you can also compare the `LoginController` / `AuthController` mechanism here, first shown with inheritance+composition, and then shown with simpler OLOO-style delegation: https://github.com/getify/You-Dont-Know-JS/blob/master/this%20&%20object%20prototypes/ch6.md#simpler-design https://github.com/getify/You-Dont-Know-JS/blob/master/this%...
- jkrems 13y agoAh, thanks. That clarifies things. Neat!