打字猴:1.700455936e+09
1700455936 public class Wizard{
1700455937
1700455938 private Random rand=new Random(System.currentTimeMillis());
1700455939
1700455940 //第一步
1700455941
1700455942 public int first(){
1700455943
1700455944 System.out.println(“执行第一个方法……”);
1700455945
1700455946 return rand.nextInt(100);
1700455947
1700455948 }
1700455949
1700455950 //第二步
1700455951
1700455952 public int second(){
1700455953
1700455954 System.out.println(“执行第二个方法……”);
1700455955
1700455956 return rand.nextInt(100);
1700455957
1700455958 }
1700455959
1700455960 //第三个方法
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
[ 上一页 ]  [ :1.700455936e+09 ]  [ 下一页 ]