|
Delphi |
|
Interface declared as type, derived from some interface:
type
INewInterface = interface
['{BE599288-2A1C-44CA-A5FA-1FDB40379A91}']
function SomeFunction: Integer;
end;
All interfaces are inherited from IUnknown, so if the ancestor is not specified, interface is derived from IUnknown. The following declarations are identical:
INewInterface = interface(IUnknown)
INewInterface = interface
Interface can be inherited when creating new interface:
type
INewSpecialInterface = interface(INewInterface)
['{E14EE8E4-4900-41C6-BB2F-4FF824FF75B7}']
function AnotherFunction: Boolean;
end;
Interfaces can be realized in any class:
type
TNewObject = class(TInterfacedObject,INewInterface,INewSpecialInterface)
public
// realization of interfaces methods
function SomeFunction: Integer;
function AnotherFunction: Boolean;
end;
You can use aliases for realization interface methods:
type
TNewObject = class(TInterfacedObject,INewInterface,INewSpecialInterface)
public
// alias declaration
function INewInterface.SomeFunction = SomeClassFunction;
function INewSpecialInterface.SomeFunction = SomeAnotherFunction;
// class methods
function SomeClassFunction: Integer;
function AnotherClassFunction: Boolean;
end;
If you have a property of an interface type (or a class type that implements the methods of an interface) you can use implements to specify that the methods of that interface are delegated to the object or interface reference which is the value of the property. Property type must relate to the class, realized needed interface, methods of this interface or interface inherited from needed interface:
type
TNewObject = class(TInterfacedObject,INewInterface)
public
function GetSomeProperty: TNewInterfacedObject;
property SomeProperty: TNewInterfacesObject read GetSomeProperty implements INewInterface;
end;
|
|
C# |
|
|
|
|
|
|
|
|