-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathOperation.cs
More file actions
48 lines (42 loc) · 823 Bytes
/
Operation.cs
File metadata and controls
48 lines (42 loc) · 823 Bytes
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
namespace SimpleFactoryPattern;
public class Operation
{
public double NumberA { get; set; }
public double NumberB { get; set; }
public virtual double GetResult()
{
return 0;
}
}
public class OperationAdd : Operation
{
public override double GetResult()
{
return NumberA + NumberB;
}
}
public class OpertaionSub : Operation
{
public override double GetResult()
{
return NumberA - NumberB;
}
}
public class OperationMul : Operation
{
public override double GetResult()
{
return NumberA * NumberB;
}
}
public class OperationDiv : Operation
{
public override double GetResult()
{
if (NumberB == 0)
{
throw new Exception("除数不能为0");
}
return NumberA / NumberB;
}
}