5 ms·
Huge fan of this article. Makes some really great points! Wish I could share and vote it up a thousand times. :) I have been writing about exactly this topic,
by _getify 13y ago
Huge fan of this article. Makes some really great points! Wish I could share and vote it up a thousand times. :)
I have been writing about exactly this topic, of why classes don't make sense (specifically for JS), in my second title of the "You Don't Know JS" book series, "this & Object Prototypes".
In particular, Chapter 6 makes the case for an alternate pattern to class-orientation design, which I call OLOO (objects-linked-to-other-objects) style code. OLOO implements the "behavior delegation" design pattern, and embraces simply peer objects linked together, instead of the awkwardness of parent-child abstract class semantics.
https://github.com/getify/You-Dont-Know-JS/blob/master/this%20%26%20object%20prototypes/ch6.md https://github.com/getify/You-Dont-Know-JS/blob/master/this%...
- tasty_freeze 13y agoKyle, the figures (fig4.png, fig5.png) are missing from that page. Other pages too. I'm one of your kickstarter contributors, but I was unable to read & review some of the chapters because significant parts of the text refer to missing diagrams.
- _getify 13y agoThey're coming. It's an artifact of working with a book publisher and the art department and all that. Sorry for the confusion.
- tasty_freeze 13y agoA rough, hand drawn sketch scanned to gif or png until the official artwork is ready would be 100x better than a broken link.
- _getify 13y agoOK, draft figures posted now. https://github.com/getify/You-Dont-Know-JS/tree/master/this%20%26%20object%20prototypes https://github.com/getify/You-Dont-Know-JS/tree/master/this%...
- jkrems 13y ago"objects-linked-to-other-objects" - why not use the established "composition over inheritance": http://en.wikipedia.org/wiki/Composition_over_inheritance http://en.wikipedia.org/wiki/Composition_over_inheritance Or does it mean something else?
- _getify 13y agoOLOO is quite different from both inheritance and composition. It embraces delegation rather than covering it up or running away from it. :)
- jkrems 13y agoCan 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!