1700468699
1700468700
1700468701
图21-9 增加父查询的类图
1700468702
1700468703
看类图中,在Corp类中增加了两个方法,setParent是设置父节点是谁,getParent是查找父节点是谁,我们来看一下程序的改变,如代码清单21-25所示。
1700468704
1700468705
代码清单21-25 抽象构件
1700468706
1700468707
public abstract class Corp{
1700468708
1700468709
//公司每个人都有名称
1700468710
1700468711
private String name=””;
1700468712
1700468713
//公司每个人都职位
1700468714
1700468715
private String position=””;
1700468716
1700468717
//公司每个人都有薪水
1700468718
1700468719
private int salary=0;
1700468720
1700468721
//父节点是谁
1700468722
1700468723
private Corp parent=null;
1700468724
1700468725
public Corp(String_name,String_position,int_salary){
1700468726
1700468727
this.name=_name;
1700468728
1700468729
this.position=_position;
1700468730
1700468731
this.salary=_salary;
1700468732
1700468733
}
1700468734
1700468735
//获得员工信息
1700468736
1700468737
public String getInfo(){
1700468738
1700468739
String info=””;
1700468740
1700468741
info=“姓名:”+this.name;
1700468742
1700468743
info=info+”\t职位:”+this.position;
1700468744
1700468745
info=info+”\t薪水:”+this.salary;
1700468746
1700468747
return info;
1700468748
[
上一页 ]
[ :1.700468699e+09 ]
[
下一页 ]