Skip to content

Instantly share code, notes, and snippets.

@HDBandit
Last active December 15, 2015 19:31
Show Gist options
  • Save HDBandit/bb373164b067c48e16b2 to your computer and use it in GitHub Desktop.
Save HDBandit/bb373164b067c48e16b2 to your computer and use it in GitHub Desktop.
// new interface
public interface CarChecker {
boolean check(Car car);
}
...
//business logic
public static List<Car> filterCars(List<Car> cars, CarChecker carChecker) {
ArrayList<Car> filteredCars = new ArrayList<Car>();
for (Car car : cars) {
if (carChecker.check(car)) {
filteredCars.add(car);
}
}
return filteredCars;
}
...
// from your program
List<Car> filter1 = filterCars(input, new BrandCarChecker());
List<Car> filter2 = filterCars(input, new BrandAndColorCarChecker());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment