I'm fairly new to object oriented programming and have a question I've stumbled upon regarding inheritance best practice.
I'm building a system for weapons in a game. I have a base class called
Weapon and two subclasses –
Projectile (such as knives and guns) – inheriting from
All weapons have stats (like Attack Point) and parts (like Grip, Magazine and Blade). Booth guns and knives have Attack Point and Grip. But only guns have Magazines and only knives have Blade.
My question here is how to think when inheriting from
Thematically a weapon consist of parts so it would make sense to have the classes
Projectilebe in charge of all the parts that weapon consist of, so
Meleehave a Grip and a Blade, and
Projectilehave a Grip and a Magazine. But then I would duplicate the Grip field.
Since both weapon types have Grip, should Grip be a part of the base class
Weapon? It feels weird to break out Grip and put it by itself in another class.
Weaponhold all parts, even if the subclasses don't use all of them? But the it feels like I will bloat the
Is there some sort of best practice? Thank you!