Let's say we've got the following:
IFirst = Interface(IUnknown)
function GetStuff: Integer;
end;
ISecond = Interface(IUnknown)
function GetOtherStuff: Integer;
end;
TFirstSecond = class(TInterfacedObject, IFirst, ISecond)
private
function GetStuff: Integer; //implementation of IFirst
function GetOtherStuff: Integer; //implementation of ISecond;
end;
I have never liked the fact that in TInterfacedObject there seems to be no way to distinguish between which methods implement which interfaces. Am I missing something? Does anyone know a way structure the code to do that? To designate that GetStuff is the implementation of IFirst and GetOtherStuff is the implementation of ISecond? ('Put a comment' is not the answer I'm looking for...)
I know I can use the 'implements' directive to define properties in TFirstSecond for each interface and delegate the implementations to instances contained within TFirstSecond, thereby segregating everything. But I'd like a shortcut...
A class can implement multiple interfaces and many classes can implement the same interface. A class can implement multiple interfaces and many classes can implement the same interface. Final method can't be overridden. Thus, an abstract function can't be final.
In Kotlin, a class can implement multiple interfaces. This is common knowledge. A class can also use delegation to implement numerous interfaces where the implementations come from any delegated objects passed into the constructor.
We can implement multiple Java Interfaces by a Java class. All methods of an interface are implicitly public and abstract. The word abstract means these methods have no method body, only method signature. Java Interface also represents the IS-A relationship of inheritance between two classes.
I suppose the only thing you can really do without using comments is to add method resolution clauses:
IFirst = interface
function GetStuff: Integer;
end;
ISecond = interface
function GetOtherStuff: Integer;
end;
TFirstSecond = class(TInterfacedObject, IFirst, ISecond)
private
function GetStuff: Integer;
function GetOtherStuff: Integer;
public
function IFirst.GetStuff = GetStuff;
function ISecond.GetOtherStuff = GetOtherStuff;
end;
I don't think this really adds very much to the mix, and I personally would consider this worse than without the method resolution clauses.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With