How to implement multiple inheritance in delphi?

前端 未结 9 791
一向
一向 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:56

    Use interfaces. Something like this (Off the top of my head, based on your description.....)

    type
    
      IBikeWheel = interface
        ...
      end;
    
      IXYZ = interface
        ...
      end;
    
      IFrontWheel = interface(IBikeWheel)
        ...
      end;
    
    
      TBike = class
        ...
      end;
    
      TBikeWheel = class(TObject, IBikeWheel);
    
      TBikeWheelXYZ = class(TBikeWheel, IXYZ);
    
      TBikeFrontWheelXYZ = class(TBikeWheelXYZ, IFrontWheel);
    

    Then implement classes for the interfaces that do what the corresponding classes in your old (presumably C/C++) library does and instantiate them in the corresponding class's constructor.

提交回复
热议问题