Basically i’m asking how best to do this properly based on what I THINK I want.
I have a weapon class which is abstract because it contains methods like Fire() that are so general (lasers vs bullets) in how they’d fire they require the inheritor implement.
however once I get to an actual ballistic weapon class which inherits from weapon class.
well most of those fire the same. They spawn the projectile and lower the ammo count and wait for the reload timer to kick down to 0 before allowing fire again.
Whether it’s a tank gun or a pistol or a turret or an artillery it will stay the same more than change.
That seems like a virtual class (a torpedo launcher might need a special implementation to raise and lower a hatch door to fire so it can’t be non-virtual/abstract, it needs to be modifiable)
however basically I want to have
abstract weapon class Fire() method
virtual ballistic weapon inherits weapon Fire() method
But it doesnt seem that you can override an abstract method and make it a virtual one.
I don’t think I want a whole new method though because i’d like to be able to do
weapon.fire
and it go into ballstic weapon and use the implementation there, unless the specific ballistic weapon has overridden that general method.
but will this work? class A { abstract fire(); } class B : A { override fire(); } class C : B { // override again (does this have to be sealed for some reason?) override fire{}; } class D : B { //do nothing just use B's implementation }
– sparkzbarcaNot an answer, please post as comment instead.
– numberkruncherack my bad wasn't paying attention (remove downvote please)
– sparkzbarcaNo problem :) I have updated my answer for you.
– numberkruncheryea i knew sealed meant that i was just making sure. Basically I wasn't sure if you were throwing sealed in there just for like exposition or if it was required. Basically i'm going to mark as answered and I believe as i'm understanding it that pseudo code i wrote would work. I can do weapon to ballistic weapon and define it and then inherit ballistic weapon and if i want i can override it, if i do nothing it uses parent (ballistic weapon) implementation. It all works out and really i just need to ignore the virtual keyword cause its virtual implicitly
– sparkzbarca