I'm doing a full rewrite of an old library, and I'm not sure how to handle this situation (for the sake of being understood, all hail the bike analogy):
I have the following classes:
TBike
- the bike itself
TBikeWheel
- one of the bike's wheel
TBikeWheelFront
and TBikeWheelBack
, both inherits from TBikeWheel
and then implements the specific stuff they need on top of it
This is pretty straightforward, but now I decide to create multiple kind of bikes, each bikes having it's own kinds of wheel - they do the same stuff as a regular front/back wheels, plus the specific for that bike.
TBikeXYZ
- inherits from TBike
TBikeWheelXYZ
- inherits from TBikeWheel
And here is my problem: TBikeWheelFrontXYZ
should inherit from TBikeWheelXYZ
(to get the specific methods of an XYZ wheel), but it should also inherit from TBikeWheelFront
(to get the specific methods of a front wheel).
My question here is, how can I implement that in a way that doesn't:
- feel like a hack
- force me to rewrite the same code several time
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…