Zeke
Composition over Inheritance
My architecture is currently as follows:
Unit C# object
Behaviours (Attack, Health, Targeting, Movement, etc) component based so I add and remove as needed.
However, the way I currently use composition is I have an AssassinAttackComponent, MageAttackComponent, DefaultAttackComponent, etc.
I feel like there are some logic that I reuse between all 3 of these (and more to come), but I don't want to inherit from these as that would break the push for composition over inheritance right? At that point my class attack components would be inheriting from DefaultAttackComponent, all of them.
Advice?
4 replies
Help with Generics
Here is my current code:
StatAttackRange/StatAttackDamage inherit from CharacterStat
I feel like it's inelegant, and I believe the solution is to use generics. But when I try to make a generic function (see below) I'm doing something wrong and I'm not sure what.
https://i.imgur.com/tTW44Y9.png
25 replies