1700456051
System.out.println(“执行第二个方法……”);
1700456052
1700456053
return rand.nextInt(100);
1700456054
1700456055
}
1700456056
1700456057
//第三个方法
1700456058
1700456059
private int third(){
1700456060
1700456061
System.out.println(“执行第三个方法……”);
1700456062
1700456063
return rand.nextInt(100);
1700456064
1700456065
}
1700456066
1700456067
//软件安装过程
1700456068
1700456069
public void installWizard(){
1700456070
1700456071
int first=this.first();
1700456072
1700456073
//根据first返回的结果,看是否需要执行second
1700456074
1700456075
if(first>50){
1700456076
1700456077
int second=this.second();
1700456078
1700456079
if(second>50){
1700456080
1700456081
int third=this.third();
1700456082
1700456083
if(third>50){
1700456084
1700456085
this.first();
1700456086
1700456087
}
1700456088
1700456089
}
1700456090
1700456091
}
1700456092
1700456093
}
1700456094
1700456095
}
1700456096
1700456097
将三个步骤的访问权限修改为private,同时把InstallSoftware中的方法installWizad移动到Wizard方法中。通过这样的重构后,Wizard类就只对外公布了一个public方法,即使要修改first方法的返回值,影响的也仅仅只是Wizard本身,其他类不受影响,这显示了类的高内聚特性。
1700456098
1700456099
对InstallSoftware类进行少量的修改,如代码清单5-12所示。
1700456100
[
上一页 ]
[ :1.700456051e+09 ]
[
下一页 ]