Say I have two classes
class Driver{
//attributes of driver ,ex: driving licence number
// methods related to driving ,ex: drive(Car) , stop(Car)
changeTyre(Car,Tyre); // sometimes the driver can change the tyres right?
}
class Mechanic{
// Hard mechanical stuff , ex: repairEngine(Car)
changeTyre(Car,Tyre); // Simple.hence sometimes the driver also does
}
Now the implementations of the two changeTyre()
methods will be the same.
Now I have two issues,
- There is a repetition (duplication) of code
- It doesn't seem meaningful to have a Super class containing the
changeTyre(Car,Tyre)
method
How these kind of situations handled?