打字猴:1.700455961e+09
1700455961
1700455962 public int third(){
1700455963
1700455964 System.out.println(“执行第三个方法……”);
1700455965
1700455966 return rand.nextInt(100);
1700455967
1700455968 }
1700455969
1700455970 }
1700455971
1700455972 在Wizard类中分别定义了三个步骤方法,每个步骤中都有相关的业务逻辑完成指定的任务,我们使用一个随机函数来代替业务执行的返回值。软件安装InstallSoftware类如代码清单5-9所示。
1700455973
1700455974 代码清单5-9  InstallSoftware类
1700455975
1700455976 public class InstallSoftware{
1700455977
1700455978 public void installWizard(Wizard wizard){
1700455979
1700455980 int first=wizard.first();
1700455981
1700455982 //根据first返回的结果,看是否需要执行second
1700455983
1700455984 if(first>50){
1700455985
1700455986 int second=wizard.second();
1700455987
1700455988 if(second>50){
1700455989
1700455990 int third=wizard.third();
1700455991
1700455992 if(third>50){
1700455993
1700455994 wizard.first();
1700455995
1700455996 }
1700455997
1700455998 }
1700455999
1700456000 }
1700456001
1700456002 }
1700456003
1700456004 }
1700456005
1700456006 根据每个方法执行的结果决定是否继续执行下一个方法,模拟人工的选择操作。场景类如代码清单5-10所示。
1700456007
1700456008 代码清单5-10 场景类
1700456009
1700456010 public class Client{
[ 上一页 ]  [ :1.700455961e+09 ]  [ 下一页 ]