- Home /
override a base property or make a new one for inheritor?
Another inheritance question on best practice.
if i have weapon property
get projectile
set projectile
and
ballistic weapon
but ballistic weapon has a ballistic projectile (which inherits from projectile)
do/should I make a new property or override the old one or what.
Basically ballistic weapon class has a projectile (and inherits the get/set property for a projectile from its base class weapon)
however it more specifically has a ballistic projectile which has things like projectile speed that a non ballistic laser weapon doesn't.
So should I override the original getter/setter and have the original getter/setter be virtual or do I make a new getter/setter
I'm concerned if i make a new one that i'd end up with 2 nearly identical properties for one weapon.
it'd have the get projectile & get ballistic projectile when really the ballistic is probably all it needs (since it inherits it can do the generic stuff still as well as specific)
But I was wanting to make sure that is how people who have dealt with inheritance more would do it.
Answer by asafsitner · Apr 30, 2013 at 06:04 AM
I say use one getter, since you can access all the 'weapon' properties just as well. It seems redundant to have two separate getters.
Except I'd maybe implement it all through interfaces (if you're composite weapons then definitely use interfaces) but yeah, polymorphism was invented to solve exactly that kind of problem. :)
yea i think i'm supposed to used covariance to keep the ability to assign them to eachother. Working out what that means exactly now. :)
Your answer
Follow this Question
Related Questions
An OS design issue: File types associated with their appropriate programs 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Update base class variable value to pass it between subclasses already attached to game objects 2 Answers
Custom Editor Properties Revert to Defaults on Play 4 Answers