program PlayWithInterfaces;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.StrUtils,
System.SysUtils,
PlayWithInterfaces.Intf
in '
PlayWithInterfaces.Intf.pas',
PlayWithInterfaces.Impl.Basic
in '
PlayWithInterfaces.Impl.Basic.pas',
PlayWithInterfaces.Impl.Split
in '
PlayWithInterfaces.Impl.Split.pas',
PlayWithInterfaces.Impl.Aggregated
in '
PlayWithInterfaces.Impl.Aggregated.pas',
PlayWithInterfaces.Impl.Contained
in '
PlayWithInterfaces.Impl.Contained.pas',
PlayWithInterfaces.Impl.Routed
in '
PlayWithInterfaces.Impl.Routed.pas',
PlayWithInterfaces.Impl.Attached
in '
PlayWithInterfaces.Impl.Attached.pas';
procedure WorkWithBar( Bar: IBar;
const Info:
string );
begin
Writeln( '
Bar - ', Info );
Writeln( '
Bar.GetBarInfo = ', Bar.GetBarInfo );
Writeln( '
Bar ', IfThen( Supports( Bar, IFoo ), '
', '
NOT ' ), '
supports IFoo' );
Writeln( '
Bar ', IfThen( Supports( Bar, IFooBar ), '
', '
NOT ' ), '
supports IFooBar' );
Writeln;
end;
procedure WorkWithFoo( Foo: IFoo;
const Info:
string );
begin
Writeln( '
Foo - ', Info );
Writeln( '
Foo.GetFooInfo = ', Foo.GetFooInfo );
Writeln( '
Foo ', IfThen( Supports( Foo, IBar ), '
', '
NOT ' ), '
supports IBar' );
Writeln( '
Foo ', IfThen( Supports( Foo, IFooBar ), '
', '
NOT ' ), '
supports IFooBar' );
Writeln;
end;
procedure WorkWithFooBar( FooBar: IFooBar;
const Info:
string );
begin
Writeln( '
FooBar - ', Info );
Writeln;
WorkWithBar( FooBar.Bar, '
FooBar.Bar' );
WorkWithFoo( FooBar.Foo, '
FooBar.Foo' );
Writeln( '
FooBar ', IfThen( Supports( FooBar, IBar ), '
', '
NOT ' ), '
supports IBar' );
Writeln( '
FooBar ', IfThen( Supports( FooBar, IFoo ), '
', '
NOT ' ), '
supports IFoo' );
Writeln;
end;
procedure Main;
var
lAttached: TAttachedFooBar;
begin
WorkWithFooBar( TBasicFooBar.Create, TBasicFooBar.ClassName );
WorkWithFooBar( TSplitFooBar.Create, TSplitFooBar.ClassName );
WorkWithFooBar( TAggregatedFooBar.Create, TAggregatedFooBar.ClassName );
WorkWithFooBar( TContainedFooBar.Create, TContainedFooBar.ClassName );
WorkWithFooBar( TRoutedFooBar.Create, TRoutedFooBar.ClassName );
lAttached := TAttachedFooBar.Create;
try
WorkWithFooBar( lAttached, lAttached.ClassName );
finally
lAttached.Free;
end;
end;
begin
ReportMemoryLeaksOnShutdown := True;
try
Main;
except
on E:
Exception do
Writeln( E.ClassName, '
: ', E.
Message );
end;
ReadLn;
end.