-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhello.helloworld.pas
More file actions
53 lines (44 loc) · 1.23 KB
/
hello.helloworld.pas
File metadata and controls
53 lines (44 loc) · 1.23 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
unit Hello.HelloWorld;
{$mode ObjFPC}{$H+}
interface
uses
Classes, SysUtils,
Hello.IHelloWorld,
Hello.IHelloWorldString,
Hello.IPrintStrategy,
Hello.IStatusCode,
Hello.EPrintStrategyError,
Hello.HelloWorldFactory;
type
/// <summary>
/// Represents the core Hello World application logic.
/// </summary>
THelloWorld = class
/// <summary>
/// Initializes a new instance of the <c>THelloWorld</c> class and
/// executes the print strategy.
/// </summary>
/// <exception cref="EPrintStrategyError">
/// Raised if printing fails due to a non-zero status code returned by the
/// print strategy.
/// </exception>
constructor Create;
end;
implementation
constructor THelloWorld.Create;
var
Factory: THelloWorldFactory;
HelloWorld: IHelloWorld;
HelloString: IHelloWorldString;
Strategy: IPrintStrategy;
Code: IStatusCode;
begin
Factory := THelloWorldFactory.GetInstance;
HelloWorld := Factory.CreateHelloWorld;
HelloString := HelloWorld.GetHelloWorldString;
Strategy := HelloWorld.GetPrintStrategy;
Code := HelloWorld.Print(Strategy, HelloString);
if Code.GetStatusCode <> 0 then
raise EPrintStrategyError.CreateFmt('Failed to print: [HW%d]', [Code.GetStatusCode]);
end;
end.