假设我有两节课
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
}
现在这两种changeTyre()
方法的实现将是相同的。
现在我有两个问题,
- 存在重复(重复)代码
changeTyre(Car,Tyre)
拥有一个包含该方法的 Super 类似乎没有意义
这类情况如何处理?