1 简单工厂模式
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了1 简单工厂模式相关的知识,希望对你有一定的参考价值。
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
}
合成(组合)是一种强的“拥有”关系,体现了严格的部分和整体的关系,部分和整体的生命周期一样。
<wiz_tmp_tag id="wiz-table-range-border" contenteditable="false" style="display: none;">
以上是关于1 简单工厂模式的主要内容,如果未能解决你的问题,请参考以下文章