1700483800
public static void main(String[]args){
1700483801
1700483802
//首先初始化一批用户
1700483803
1700483804
ArrayList<User>userList=new ArrayList<User>();
1700483805
1700483806
userList.add(new User(“苏大”,3));
1700483807
1700483808
userList.add(new User(“牛二”,8));
1700483809
1700483810
userList.add(new User(“张三”,10));
1700483811
1700483812
userList.add(new User(“李四”,15));
1700483813
1700483814
userList.add(new User(“王五”,18));
1700483815
1700483816
userList.add(new User(“赵六”,20));
1700483817
1700483818
userList.add(new User(“马七”,25));
1700483819
1700483820
userList.add(new User(“杨八”,30));
1700483821
1700483822
userList.add(new User(“侯九”,35));
1700483823
1700483824
userList.add(new User(“布十”,40));
1700483825
1700483826
//定义一个用户查询类
1700483827
1700483828
IUserProvider userProvider=new UserProvider(userList);
1700483829
1700483830
//打印出年龄大于20岁的用户
1700483831
1700483832
System.out.println(”===年龄大于20岁的用户===”);
1700483833
1700483834
//定义一个规格书
1700483835
1700483836
IUserSpecification userSpec=new UserByAgeThan(20);
1700483837
1700483838
for(User u:userProvider.findUser(userSpec)){
1700483839
1700483840
System.out.println(u);
1700483841
1700483842
}
1700483843
1700483844
}
1700483845
1700483846
}
1700483847
1700483848
在场景类中定义了一个规格书,然后把规格书提交给UserProvider就可以查找到自己需要的用户了,运行结果相同,不再赘述。
1700483849
[
上一页 ]
[ :1.7004838e+09 ]
[
下一页 ]