1700463961
System.out.println(“儿子的答复是:同意”);
1700463962
1700463963
}
1700463964
1700463965
}
1700463966
1700463967
以上三个实现类非常简单,只有一个方法,处理女儿、妻子、母亲提出的请求,我们来模拟一下一个古代妇女出去逛街是如何请示的,如代码清单16-7所示。
1700463968
1700463969
代码清单16-7 场景类
1700463970
1700463971
public class Client{
1700463972
1700463973
public static void main(String[]args){
1700463974
1700463975
//随机挑选几个女性
1700463976
1700463977
Random rand=new Random();
1700463978
1700463979
ArrayList<IWomen>arrayList=new ArrayList();
1700463980
1700463981
for(int i=0;i<5;i++){
1700463982
1700463983
arrayList.add(new Women(rand.nextInt(4),“我要出去逛街”));
1700463984
1700463985
}
1700463986
1700463987
//定义三个请示对象
1700463988
1700463989
IHandler father=new Father();
1700463990
1700463991
IHandler husband=new Husband();
1700463992
1700463993
IHandler son=new Son();
1700463994
1700463995
for(IWomen women:arrayList){
1700463996
1700463997
if(women.getType()==1){//未结婚少女,请示父亲
1700463998
1700463999
System.out.println(”\n––—女儿向父亲请示––-“);
1700464000
1700464001
father.HandleMessage(women);
1700464002
1700464003
}else if(women.getType()==2){//已婚少妇,请示丈夫
1700464004
1700464005
System.out.println(”\n––—妻子向丈夫请示––-“);
1700464006
1700464007
husband.HandleMessage(women);
1700464008
1700464009
}else if(women.getType()==3){//母亲请示儿子
1700464010
[
上一页 ]
[ :1.700463961e+09 ]
[
下一页 ]