C#C
C#3y ago
Tijmen

Inheritance

I'm trying to create a setup where the data and logic of my weapons are separate. Hence there being a Weapon class, and WeaponData.

We have many types of weapons, that also inherit deeply. Think Pistol inherits from SingleShotWeapon which inherits from FireArm which inherits from Weapon. Usually each type also has a separate config class, WeaponData_Pistol.

I'm struggling to find a way to nicely have this sub-class defined in the class itself. The deep inheritance chain makes generics difficult, i cant just add a generic field and constraint to Weapon and end that chain at any point since it will be inherited even further.

It also means we need to construct our class like this: `new FireArm<FireArmData>, which is a bit odd. It should always use a FireArmData.
image.png
Was this page helpful?