Created
November 26, 2019 07:58
-
-
Save hongbeomi/d84a8b6b77e3d72947cffa2d4d7eec9a to your computer and use it in GitHub Desktop.
This file contains 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
// 모든 속성을 메서드 파라미터로 추가한 모습 (끔찍) | |
public static List<Apple> filterApples(List<Apple> inventory, Color color, int weight, boolean flag) { | |
List<Apple> result = new ArrayList<>(); | |
for (Apple apple: inventory) { | |
if ( (flag && apple.getColor().equals(color)) || (!flag && apple.getWeight() > weight) ){ | |
result.add(apple); | |
} | |
} | |
return result; | |
} | |
// 이렇게 사용할 수 있다 (이 방법은 사용하지 말아야 한다..) | |
List<Apple> greenApples = filterApples(inventory, GREEN, 0, true); | |
List<Apple> heavyApples = filterApples(inventory, null, 150, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment