What is the difference between these two pieces of code
type IInterface1 = interface procedure Proc1; end; IInterface2 = interface procedure Proc2; end; TMyClass = class(TInterfacedObject, IInterface1, IInterface2) protected procedure Proc1; procedure Proc2; end;
And the following :
type IInterface1 = interface procedure Proc1; end; IInterface2 = interface(Interface1) procedure Proc2; end; TMyClass = class(TInterfacedObject, IInterface2) protected procedure Proc1; procedure Proc2; end;
If they are one and the same, are there any advantages, or readability issues with either.
I guess the second means you cannot write a class that implements IInterface2 without implementing IInterface1, whilst with the first you can.
First off, I’m assuming that the second example’s declaration for IInterface2 is a typo and should be
because inheriting from itself is nonsensical (even if the compiler accepted it).
And ‘inheriting’ is the key word there for answering your question. In example 1 the two interfaces are completely independent and you can implement one, the other, or both without problems. In example 2, you are correct that you can’t implement interface2 without also implementing interface1, but the reason why that’s so is because it makes interface1 a part of interface2.
The difference, then, is primarily structural and organizational, not just readability.