C#C
C#2y ago
3 replies
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?
Was this page helpful?