A collection of Bad Code Smells in a Catalog form for Developers & Researchers. Code Smell is a typical bad code implementation, and learning these concepts immiedietly makes you a better developer!
At that point I would argue composition/traits are the way to go.
“This extends Draggable”. That’s great but now we can’t extend “Button” to override the click handler.
Traits:
You wanna have Health, and do Damage, but don’t want to implement InventoryItem? No problem.
You wanna be an Enemy and InventoryItem? Go for it.
What’s this function take? Anything that implements InventoryItem + Consumable
The only reason why traits are considered better is because in languages like rust it can enable static dispatch. Whereas interfaces in C#, Java, Typescript, (and C++ via abstract classes, not templates) are always dynamic dispatch.
inheritance rarely solves anything
You gotta know how to use it properly
At that point I would argue composition/traits are the way to go.
“This extends Draggable”. That’s great but now we can’t extend “Button” to override the click handler.
Traits: You wanna have Health, and do Damage, but don’t want to implement InventoryItem? No problem. You wanna be an Enemy and InventoryItem? Go for it. What’s this function take? Anything that implements InventoryItem + Consumable
use an interface?
Yeah Interfaces would be the next best thing.
The only reason why traits are considered better is because in languages like rust it can enable static dispatch. Whereas interfaces in C#, Java, Typescript, (and C++ via abstract classes, not templates) are always dynamic dispatch.