public class OperationFactory {
public static Operation createOperate(String operate) {
Operation oper = null;
switch (operate) {
case "+":
oper = new OperationAdd();
break;
case "-":
oper = new OperationSub();
break;
case "*":
oper = new OperationMul();
break;
case "/":
oper = new OperationDiv();
break;
}
return oper;
}
}
20
1
public class OperationFactory {
2
public static Operation createOperate(String operate) {
3
Operation oper = null;
4
switch (operate) {
5
case "+":
6
oper = new OperationAdd();
7
break;
8
case "-":
9
oper = new OperationSub();
10
break;
11
case "*":
12
oper = new OperationMul();
13
break;
14
case "/":
15
oper = new OperationDiv();
16
break;
17
}
18
return oper;
19
}
20
}
![](https://i-blog.csdnimg.cn/blog_migrate/e0a45c5a8672b1aef78325d440a42924.png)
合成(组合)是一种强的“拥有”关系,体现了严格的部分和整体的关系,部分和整体的生命周期一样。
<wiz_tmp_tag id="wiz-table-range-border" contenteditable="false" style="display: none;">