-
Notifications
You must be signed in to change notification settings - Fork 0
/
UCalculationMethods.pas
49 lines (37 loc) · 1.01 KB
/
UCalculationMethods.pas
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
unit UCalculationMethods;
interface
uses
UICalculation;
type
TCalculationMethod = class(TInterfacedObject, ICalculation)
function Calculation(a, b: Integer): Integer; virtual; abstract;
end;
TAddition = class sealed(TCalculationMethod)
function Calculation(a1, a2: Integer): Integer; override; final;
end;
type
TMultiplication = class sealed(TCalculationMethod)
function Calculation(m1, m2: Integer): Integer; override; final;
end;
type
TMultiplicationPerAddition = class sealed(TCalculationMethod)
function Calculation(i1, i2: Integer): Integer; override; final;
end;
implementation
function TAddition.Calculation(a1, a2: Integer): Integer;
begin
Result := a1 + a2;
end;
function TMultiplication.Calculation(m1, m2: Integer): Integer;
begin
Result := m1 * m2;
end;
function TMultiplicationPerAddition.Calculation(i1, i2: Integer): Integer;
begin
Result := 0;
for var i: Integer := 1 to i1 do
begin
Result := Result + i2;
end;
end;
end.