-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[노영재] 1차 과제 제출 #3
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
잠시 잊고 있었던 getOrDefault 메서드를 상기시킬 수 있어서 좋았습니다.
public static ItemHandler getHandler(Item item) { | ||
return handlerMap.getOrDefault(item.name, new RegularItemHandler()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저는 일반적인 아이템에 대해서 처리하기 위해서 맵에 null 값을 넣는 방식을 사용했었는데, 영재님처럼 getOrDefault 메서드를 쓰는 것이 더 좋은 것 같습니다.
|
||
class GildedRose { | ||
Item[] items; | ||
public Item[] items; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Items 필드를 public으로 바꾼 이유가 궁금합니다! 외부에서 사용하지 않다고 판단되면 private으로 바꾸는 게 좋다고 생각합니다
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
네 그런거 같습니다 피드백 감사합니다!
} | ||
} | ||
for (Item item : items) { | ||
ItemHandler handler = ItemHandlerFactory.getHandler(item); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
팩토리 메소드를 활용해 아이템에 해당하는 핸들러를 가지고 오는 방식 인상깊었습니다
private static final Map<String, ItemHandler> handlerMap = new HashMap<>(); | ||
|
||
static { | ||
handlerMap.put("Aged Brie", new BrieItemHandler()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
핸들러 맵에 하드 코딩된 매직 넘버가 있으면 코드를 이해하기 어려울 것 같습니다. 상수화나 Item을 분류할 수 있는 Enum 값이 있으면 어떨까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
팩토리 메소드를 활용한 코드 인상 깊게 봤습니다. 질문을 하나 달아놨는데 정답은 없으니 생각 달아주시면 감사하겠습니다
No description provided.