Need opinions:
what is better in JS context composition or inheritance? What should be used when?
For further actions, you may consider blocking this person and/or reporting abuse
Need opinions:
what is better in JS context composition or inheritance? What should be used when?
For further actions, you may consider blocking this person and/or reporting abuse
horiyorrmi72 -
Jakub Andrzejewski -
Lucas Weis Polesello -
Programming with Shahan -
Once suspended, akanksha_9560 will not be able to comment or publish posts until their suspension is removed.
Once unsuspended, akanksha_9560 will be able to comment and publish posts again.
Once unpublished, all posts by akanksha_9560 will become hidden and only accessible to themselves.
If akanksha_9560 is not suspended, they can still re-publish their posts from their dashboard.
Once unpublished, this post will become invisible to the public and only accessible to Akanksha Sharma.
They can still re-publish the post if they are not suspended.
Thanks for keeping DEV Community safe. Here is what you can do to flag akanksha_9560:
Unflagging akanksha_9560 will restore default visibility to their posts.
Top comments (5)
Composition, always.
Inheritance makes components strongly coupled to their mother "class", effectively making them unusable in a different context (reusability).
With React, you implement common logic into HigherOrderComponents (HoC) which are essentially functions taking any component as parameter, to return it with extended props including the common logic.
More recently, React introduced Hooks which simplifies even more this composition pattern.
With Vue, you can do the same with "mixins", which can be imported into any component, effectively extending their core logic.
Also, writing common logic into small functions makes them highly composable, chainable and reusable with currying, which is more inline with functional programming.
Lastly, a composable HoC/mixin are much easier to unit test, than a "mother class" used in POO.
Very good points :), but what would be the circumstances we would use inheritance?
Honestly i never felt the use for it, either in front nor in a Node backend.
A usecase where inheritance could be useful would be, in a big NodeJS-based backend, to create a custom module from another module so you could extend it with your custom methods.
Best example coming to my mind is NestJS, check it out.
What is better -- fish or a hat?