1700483741
1700483742
规格书都已经定义完毕了,那我们再来看用户操作类,先看用户操作的接口,如代码清单37-9所示。
1700483743
1700483744
代码清单37-9 用户操作接口
1700483745
1700483746
public interface IUserProvider{
1700483747
1700483748
//根据条件查找用户
1700483749
1700483750
public ArrayList<User>findUser(IUserSpecification userSpec);
1700483751
1700483752
}
1700483753
1700483754
只有一个方法——根据指定的规格书查找用户。再来看其实现类,如代码清单37-10所示。
1700483755
1700483756
代码清单37-10 用户操作
1700483757
1700483758
public class UserProvider implements IUserProvider{
1700483759
1700483760
//用户列表
1700483761
1700483762
private ArrayList<User>userList;
1700483763
1700483764
//传递用户列表
1700483765
1700483766
public UserProvider(ArrayList<User>_userList){
1700483767
1700483768
this.userList=_userList;
1700483769
1700483770
}
1700483771
1700483772
//根据指定的规格书查找用户
1700483773
1700483774
public ArrayList<User>findUser(IUserSpecification userSpec){
1700483775
1700483776
ArrayList<User>result=new ArrayList<User>();
1700483777
1700483778
for(User u:userList){
1700483779
1700483780
if(userSpec.isSatisfiedBy(u)){//符合指定规格
1700483781
1700483782
result.add(u);
1700483783
1700483784
}
1700483785
1700483786
}
1700483787
1700483788
return result;
1700483789
1700483790
}
[
上一页 ]
[ :1.700483741e+09 ]
[
下一页 ]