Recent

Author Topic: Creating children of interface implementation  (Read 552 times)

reb

  • New member
  • *
  • Posts: 8
Creating children of interface implementation
« on: August 18, 2019, 10:25:02 am »
Hello all,
Here is my code:

Code: Pascal  [Select][+][-]
  1.   TEqualCollider = class(TInterfacedObject, ICollider)
  2.   const
  3.     ColliderCount = 4;
  4.   private
  5.     ColliderTop, ColliderRight, ColliderBottom, ColliderLeft: TCollider;
  6.   public
  7.     procedure InstantiateAll(AUPosition, AUSize: TPointF; AThickness: single); virtual;
  8.     procedure RegisterAll
  9.     procedure UnregisterAll;
  10.     function Count: Cardinal;
  11.     function Get(index: Cardinal): TCollider;
  12.     procedure DrawDebug(ctx: TBGLContext);
  13.   end;
  14.  
  15.   TPlatformCollider = class(TEqualCollider)
  16.   public
  17.     procedure InstantiateAll(AUPosition, AUSize: TPointF; AThickness: single); override;
  18.   end;
  19.  

I am using interfaces to define many different versions of the object collider. I would like to inherit all implementations from the TEqualCollider into TPlatformCollider, while overriding one procedure. Difference between the two is very small, I don't want to copy paste entire class.

Ive also tried this:
Code: Pascal  [Select][+][-]
  1. TPlatformCollider = class(TEqualCollider, ICollider)

The code compiles OK either way, but it does not seem to work. Is this possible to do? Maybe I should move onto multiple inheritance?

reb

  • New member
  • *
  • Posts: 8
Re: Creating children of interface implementation
« Reply #1 on: August 18, 2019, 10:30:32 am »
Ah, it was an error somewhere else in a code.
Both methods work!

I cannot delete my own post. Can someone delete this?

 

TinyPortal © 2005-2018