File tree Expand file tree Collapse file tree 1 file changed +16
-12
lines changed Expand file tree Collapse file tree 1 file changed +16
-12
lines changed Original file line number Diff line number Diff line change 4
4
``` php
5
5
<?php
6
6
7
+ /**
8
+ * Operation
9
+ */
7
10
class Operation
8
11
{
9
12
protected $a = 0;
@@ -27,8 +30,8 @@ class Operation
27
30
}
28
31
29
32
/**
30
- * add
31
- */
33
+ * Add
34
+ */
32
35
class OperationAdd extends Operation
33
36
{
34
37
public function getResult()
@@ -38,8 +41,8 @@ class OperationAdd extends Operation
38
41
}
39
42
40
43
/**
41
- * Mul
42
- */
44
+ * Mul
45
+ */
43
46
class OperationMul extends Operation
44
47
{
45
48
public function getResult()
@@ -49,8 +52,8 @@ class OperationMul extends Operation
49
52
}
50
53
51
54
/**
52
- * sub
53
- */
55
+ * Sub
56
+ */
54
57
class OperationSub extends Operation
55
58
{
56
59
public function getResult()
@@ -60,8 +63,8 @@ class OperationSub extends Operation
60
63
}
61
64
62
65
/**
63
- * div
64
- */
66
+ * Div
67
+ */
65
68
class OperationDiv extends Operation
66
69
{
67
70
public function getResult()
@@ -70,10 +73,9 @@ class OperationDiv extends Operation
70
73
}
71
74
}
72
75
73
-
74
76
/**
75
- * operation factory
76
- */
77
+ * Operation Factory
78
+ */
77
79
class OperationFactory
78
80
{
79
81
public static function createOperation($operation)
@@ -92,14 +94,16 @@ class OperationFactory
92
94
$oper = new OperationMul();
93
95
break;
94
96
}
97
+
95
98
return $oper;
96
99
}
97
100
}
101
+
98
102
// 客户端代码
99
103
$operation = OperationFactory::createOperation('+');
100
104
$operation->setA(1);
101
105
$operation->setB(2);
102
- echo $operation->getResult()."\n" ;
106
+ echo $operation->getResult() . PHP_EOL ;
103
107
```
104
108
105
109
You can’t perform that action at this time.
0 commit comments