How to implement multiple inheritance in delphi?

前端 未结 9 790
一向
一向 2020-12-03 11:22

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

9条回答
  •  醉话见心
    2020-12-03 11:54

    You can try to extract an interface, say IFrontWheel, out of TBikeWheelFront, so that it is a subclass of TBikeWheel but implements IFrontWheel. Then TBikeWheelXYZ inherits from TBikeWheel and TBikeWheelFrontXYZ inherits from TBikeWheelXYZ and implements IFrontWheel.

    Then you can define a class TFrontwheel and give it the same methods as the interface, but now you implement them. Then TBikeWheelFront and TBikeWheelXYZ get a private member of type TFrontwheel and the IFrontWheel implementations of them simply delegate to the private member methods.

    This way you don't have double implementations.

提交回复
热议问题