我感到困惑的使用来设计以下场景哪种模式,左右为难哪些使用装饰VS桥模式
Interface GearBox {
int upshift();
int downshift();
int reverse();
}
AutoGearBox implements GearBox{...}
ManualGearBox implements GearBox{...}
现在我想DualClutchGearBox添加到hierarchy.All以前的变速箱是单离合器。我该如何去做呢?
随着装饰 - >
DualClutchDecorator implements GearBox{
DualClutchDecorator(GearBox box){...}
}
随着大桥 - >
GearBox{
GearBoxImpl impl;
....
}
AutoGearBox implements GearBox{...}
ManualGearBox implements GearBox{...}
abstract class GearBoxImpl{}
SingleClutchImpl extends GearBoxImpl{...}
DualClutchImpl extends GearBoxImpl{...}
哪一个更好,为什么?
这取决于'DualClutchGearBox'如何不同于'GearBox'。 –
接口方面它是一样的,它只是在变速时使用离合器的方式不同 – LoyalBanana
所以这是内部实现 - 它不会出现在接口中。这就是接口的全部要点。 – DNA