Skip to main content
1 of 2
Vaillancourt
  • 16.4k
  • 17
  • 56
  • 61

It's not.

What if you want to hit with a shield (e.g. "Shield bash"), i.e. use an "Armor" as a "Weapon", or defend with a sword (e.g. "Parry") i.e. use a "Weapon" as an "Armor"?

You'll end up with having a Shield that inherits from Armor and from Weapon. And when you introduce diamond inheritance, you introduce guaranteed headaches.

Also, you'll end up a huge hierarchy, in which you could get lost, and in which you'll not want to modify base classes because it'll potentially mess up too much other features.

The favoured approach is to use Composition over inheritance. Basically, you add behaviours to your items which drive what they can do. If an "Item" has an "attack" component (which has a "damage dealt" property (for instance)) , it means that you can use it as a weapon. If the same item has a "defense" component (with a "guard ratio" property, for instance), it means that the item can be used as an "armour".

Another research term is component based architecture. This should get you re-thinking your architecture :)

Vaillancourt
  • 16.4k
  • 17
  • 56
  • 61