© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
9 replies
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
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Inheritance
C#CC# / help
15mo ago
✅ inheritance
C#CC# / help
2y ago
❔ Inheritance
C#CC# / help
3y ago
❔ inheritance??
C#CC# / help
3y ago