My question is about OOP, and best practice writing in C# for Unity.
Say I'm writing components for an item system.
Consumables have quantity.
Weapons have durability, damage, block and stats.
Armour has durability, armour and stats.
Shield has durability, block, armour and stats.
In this situation, should I...
- write a Consumable component, Weapon component, Shield component and Armour component that each extend an Item class?
- write a Quantity component, Durability component, Damage component, Block component, Armour component and Stats component, then add as required?
- write an Item component with all the possible fields plus an enum that decides which ones go unused?
I like 1) because it defines the items by what they do, but there's repetition of fields horizontally in the inheritance tree.
I like 2) because there's no repetition, but it allows for the creation of items that don't make sense. There's no strict definition going on, just the existence or non-existence of components, and some might need to be mutually exclusive.
I like 3) because it's the solution to the problem with 1), and the enum is kind of a solution to the problem with 2), but it seems wasteful to deal with a larger data structure than required for every item.
Any thoughts?