Hello guys,
Here is an idea about a small, but effective extension for the usage of the
implements keyword.
Say we have to deal with the following piece of source code:
{$INTERFACES CORBA}
type
IUserIntf = interface
['{B817AB72-1F3E-4FE6-B406-C2B5A17E58A2}']
procedure ShowUser();
end;
IExplIntf = interface
['{B817AB72-1F3E-4FE6-B406-C2B5A17E58A2}']
procedure Explain();
end;
{ TInternalObject }
TInternalObject = class(TObject, IUserIntf, IExplIntf)
public
procedure ShowUser();
procedure Explain();
end;
{ TUserObject }
TUserObject = class(TObject, IUserIntf, IExplIntf)
private
FInteral: TInternalObject;
public
property Internal: TInternalObject read FInternal implements IUserIntf, IExplIntf;
end;
var
UserObj: TUserObject;
Situation:
The programmer might be required to have the implementer
Internal hidden from public view, but also have access to members of
IUserIntf and
IExplIntf directly through
UserObj, without querying for an interface pointer, such as:
This would require that the programmer copy-paste all the members from both interfaces and redirect each call to
Internal.
The possible solution to avoid such copy-pastes would be:
TUserObject = class(TObject, IUserIntf, IExplIntf)
private
FInteral: TInternalObject;
protected
property Internal: TInternalObject read FInternal implements
public IUserIntf,
protected IExplIntf;
end;
in which those
public UserIntf and
protected IExplIntf would make the members of
IUserIntf available as public members of
TUserObject, while those of
IExplIntf as protected members.
Advantages of this solution:
1. Hides the actual implementer
Internal, i.e. when using composition, but the implemented interface members can be accessed directly through
TUserObject.
2. Avoids manual promotion of the interface members usually done using copy-paste and a lot of boilerplate source code that, in general, it only redirects the code to the internal object.
3. Reduces a lot the time to maintain source code when the members of the interfaces change.
The compiler would do the redirection of calls as the programmer would do it manually.