打字猴:1.700456061e+09
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
1700456101 代码清单5-12 修改后的InstallSoftware类
1700456102
1700456103 public class InstallSoftware{
1700456104
1700456105 public void installWizard(Wizard wizard){
1700456106
1700456107 //直接调用
1700456108
1700456109 wizard.installWizard();
1700456110
[ 上一页 ]  [ :1.700456061e+09 ]  [ 下一页 ]