Skip to content

Instantly share code, notes, and snippets.

@ritalin
Created August 17, 2018 02:45
Show Gist options
  • Save ritalin/b93e045e9cca13d71b1ad20d4ed92f26 to your computer and use it in GitHub Desktop.
Save ritalin/b93e045e9cca13d71b1ad20d4ed92f26 to your computer and use it in GitHub Desktop.
インターフェースの委譲のオーバーライドのテスト
program InterfaceTestDriver;
{$APPTYPE CONSOLE}
uses
SysUtils;
type
IMyIntf = interface
['{D9075E8D-417D-4358-ABA0-6688B245EF6A}']
procedure P1;
procedure P2;
end;
TMyIntfAdapter = class(TInterfacedObject, IMyIntf)
private
FOwner: string;
protected
procedure P1;
procedure P2;
public
constructor Create(inOwner: string);
end;
TMyAdapter = class
private
FOwner: string;
public
procedure P1;
procedure P2;
public
constructor Create(inOwner: string);
end;
TMyAdapterPartial = class
private
FOwner: string;
public
procedure P1;
public
constructor Create(inOwner: string);
end;
TMyIntfDriver1 = class(TInterfacedObject, IMyIntf)
private
FIntf: IMyIntf;
protected
property Intf: IMyIntf read FIntf implements IMyIntf;
protected
procedure P2;
public
constructor Create;
end;
//
// TMyIntfDriver2 = class(TInterfacedObject, IMyIntf)
// private
// FIntf: IMyIntf;
// private
// procedure MyP2;
// protected
// property Intf: IMyIntf read FIntf implements IMyIntf;
// protected
// procedure IMyIntf.P2 = MyP2;
// public
// constructor Create;
// end;
TMyIntfDriver3 = class(TInterfacedObject, IMyIntf)
private
FIntf: TMyAdapter;
private
procedure MyP2;
protected
property Intf: TMyAdapter read FIntf implements IMyIntf;
protected
procedure IMyIntf.P2 = MyP2;
public
constructor Create;
end;
TMyIntfDriver4 = class(TInterfacedObject, IMyIntf)
private
FIntf: TMyIntfAdapter;
private
procedure MyP2;
protected
property Intf: TMyIntfAdapter read FIntf implements IMyIntf;
protected
procedure IMyIntf.P2 = MyP2;
public
constructor Create;
end;
TMyIntfDriver5 = class(TInterfacedObject, IMyIntf)
private
FIntf: TMyIntfAdapter;
protected
property Intf: TMyIntfAdapter read FIntf implements IMyIntf;
protected
procedure P2;
public
constructor Create;
end;
TMyIntfDriver6 = class(TInterfacedObject, IMyIntf)
private
FIntf: TMyAdapterPartial;
protected
property Intf: TMyAdapterPartial read FIntf implements IMyIntf;
protected
procedure P2;
public
constructor Create;
end;
{ TMyIntfAdapter }
constructor TMyIntfAdapter.Create(inOwner: string);
begin
FOwner := inOwner;
end;
procedure TMyIntfAdapter.P1;
begin
Writeln(Format('%s -> TMyIntfAdapter.P1 called', [FOwner]));
end;
procedure TMyIntfAdapter.P2;
begin
Writeln(Format('%s -> TMyIntfAdapter.P2 called', [FOwner]));
end;
{ TMyAdapter }
constructor TMyAdapter.Create(inOwner: string);
begin
FOwner := inOwner;
end;
procedure TMyAdapter.P1;
begin
Writeln(Format('%s -> TMyAdapter.P1 called', [FOwner]));
end;
procedure TMyAdapter.P2;
begin
Writeln(Format('%s -> TMyAdapter.P2 called', [FOwner]));
end;
{ TMyAdapterPartial }
constructor TMyAdapterPartial.Create(inOwner: string);
begin
FOwner := inOwner;
end;
procedure TMyAdapterPartial.P1;
begin
Writeln(Format('%s -> TMyAdapterPartial.P1 called', [FOwner]));
end;
{ TMyIntfDriver1 }
constructor TMyIntfDriver1.Create;
begin
FIntf := TMyIntfAdapter.Create(Self.ClassName);
end;
procedure TMyIntfDriver1.P2;
begin
Writeln('TMyIntfDriver1.P2 called');
end;
//{ TMyIntfDriver2 }
//
//constructor TMyIntfDriver2.Create;
//begin
// FIntf := TMyIntfAdapter.Create;
//end;
//
//procedure TMyIntfDriver2.MyP2;
//begin
// Writeln('TMyIntfDriver2.MyP2 called');
//end;
{ TMyIntfDriver3 }
constructor TMyIntfDriver3.Create;
begin
FIntf := TMyAdapter.Create(Self.ClassName);
end;
procedure TMyIntfDriver3.MyP2;
begin
Writeln('TMyIntfDriver3.MyP2 called');
end;
{ TMyIntfDriver4 }
constructor TMyIntfDriver4.Create;
begin
FIntf := TMyIntfAdapter.Create(Self.ClassName);
end;
procedure TMyIntfDriver4.MyP2;
begin
Writeln('TMyIntfDriver4.MyP2 called');
end;
{ TMyIntfDriver5 }
constructor TMyIntfDriver5.Create;
begin
FIntf := TMyIntfAdapter.Create(Self.ClassName);
end;
procedure TMyIntfDriver5.P2;
begin
Writeln('TMyIntfDriver5.P2 called');
end;
{ TMyIntfDriver6 }
constructor TMyIntfDriver6.Create;
begin
FIntf := TMyAdapterPartial.Create(Self.ClassName);
end;
procedure TMyIntfDriver6.P2;
begin
Writeln('TMyIntfDriver6.P2 called');
end;
var
x1, x3, x4, x5, x6: IMyIntf;
begin
try
x1 := TMyIntfDriver1.Create;
x3 := TMyIntfDriver3.Create;
x4 := TMyIntfDriver4.Create;
x5 := TMyIntfDriver5.Create;
x6 := TMyIntfDriver6.Create;
x1.P1;
x1.P2;
Writeln('----');
x3.P1;
x3.P2;
Writeln('----');
x4.P1;
x4.P2;
Writeln('----');
x5.P1;
x5.P2;
Writeln('----');
x6.P1;
x6.P2;
{ TODO -oUser -cConsole Main : ここにコードを記述してください }
Readln;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment