I have a question about derivation, polymorphism and method signature
I have a class
public abstract class PaymentMethod { public abstract float GetSalary (Employee employee,Vehicule vehicule) }
and two others
public class MarinePaymentMethod : PayementMethod { public override float GetSalary (Sailor sailor,Boat boat) } public class AirPaymentMethod : PayementMethod { public override float GetSalary (Pilot pilot,Plane plane) }
Assume also that:
public class Sailor : Employee{} public class Pilot : Employee{} public class Boat: Vehicule{} public class Plane: Vehicule{}
So, the βproblemβ is that this code does not compile because the signatures do not match.
I can save the basic signature of GetSalary (Employee employee, vehicleule vehicleule)
and then I have to use the derivative payment method so that I can use certain members of Pilot , Sailor , Boat , Plane in this particular payment method.
My first question is: is it really a bad smell?
My second question: how to make more elegant code design? I thought about Generics and created a class like this:
public abstract class PaymentMethod<T, U> where T: Employee where U: Vehicule
But then in my code I understand that I should use the generic almost everywhere I use the mehod payment class, and it makes the code heavy. Any other solutions?
thanks a lot