-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhello.helloworldimplementation.pas
More file actions
63 lines (52 loc) · 1.97 KB
/
hello.helloworldimplementation.pas
File metadata and controls
63 lines (52 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
unit Hello.HelloWorldImplementation;
{$mode ObjFPC}{$H+}
interface
uses
Classes, SysUtils, Hello.IHelloWorld, Hello.IPrintStrategy,
Hello.IStatusCode, Hello.IHelloWorldString, Hello.HelloWorldStringImplementation,
Hello.PrintStrategyFactory;
type
/// <summary>
/// Concrete implementation of the <c>IHelloWorld</c> interface.
/// Provides access to HelloWorldString and PrintStrategy,
/// and performs printing operations.
/// </summary>
THelloWorldImplementation = class(TInterfacedObject, IHelloWorld)
public
/// <summary>
/// Returns an <c>IHelloWorldString</c> instance containing the "Hello, World!" string.
/// </summary>
/// <returns>An instance implementing <c>IHelloWorldString</c>.</returns>
function GetHelloWorldString: IHelloWorldString;
/// <summary>
/// Returns a configured <c>IPrintStrategy</c> instance for printing.
/// </summary>
/// <returns>An instance implementing <c>IPrintStrategy</c>.</returns>
function GetPrintStrategy: IPrintStrategy;
/// <summary>
/// Executes printing of the given string using the specified print strategy.
/// </summary>
/// <param name="Strategy">The print strategy to use.</param>
/// <param name="Str">The string to print.</param>
/// <returns>An <c>IStatusCode</c> indicating success or failure of the print operation.</returns>
function Print(const Strategy: IPrintStrategy;
const Str: IHelloWorldString): IStatusCode;
end;
implementation
function THelloWorldImplementation.GetHelloWorldString: IHelloWorldString;
begin
Result := THelloWorldStringImplementation.Create;
end;
function THelloWorldImplementation.GetPrintStrategy: IPrintStrategy;
var
Factory: TPrintStrategyFactory;
begin
Factory := TPrintStrategyFactory.GetInstance;
Result := Factory.CreatePrintStrategy;
end;
function THelloWorldImplementation.Print(const Strategy: IPrintStrategy;
const Str: IHelloWorldString): IStatusCode;
begin
Result := Strategy.Print(Str);
end;
end.