行为参数化:就是一个方法接收多个不同的行为参数,并在内部使用他们,完成不同的行为能力。行为参数化可以更好的适应不断变化的需求,减少实际开发工作量。
现在有一些需求,苹果农场的农名将苹果采摘下来放在农场的仓库,需要从中筛选出所有绿色的苹果。
Apple类
public class Apple {
private int weight = 0;
private String color = "";
public Apple(int weight, String color){
this.weight = weight;
this.color = color;
}
public Integer getWeight() {
return weight;
}
public void setWeight(Integer weight) {
this.weight = weight;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public String toString() {
return "Apple{" +
"color='" + color + '\'' +