Last active
December 15, 2015 19:31
-
-
Save HDBandit/bb373164b067c48e16b2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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