-
Notifications
You must be signed in to change notification settings - Fork 34
[2주차] 객체지향 코드 연습(seryn6911-hub) #45
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
base: main
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.
Controller 26번줄 까지 코드리뷰한 상태입니다.
추석동안 고생하셨어요!
default String readLine() { | ||
return null; | ||
} |
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.
이 default의 의미는 무엇인가요?
public View() { | ||
this.reader = new Scan(); // Scan은 InputReader 구현체 | ||
} |
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.
헌우님이 올리신 appConfig를 읽고 적용해보세요!
인터페이스 활용은 잘하신 것 같아요.
src/main/java/lotto/view/View.java
Outdated
// 음수 또는 0 체크 | ||
if (purchasePrice <= 0) { | ||
throw new IllegalArgumentException(ErrorMessage.INVALID_AMOUNT.getMessage()); | ||
} | ||
|
||
// 1000원 단위 체크 | ||
if (purchasePrice % 1000 != 0) { | ||
throw new IllegalArgumentException(ErrorMessage.INVALID_AMOUNT.getMessage()); | ||
} |
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.
값을 검사하는 객체가 있으면 더 좋을 것 같아요
import java.util.List; | ||
|
||
public class Lotto_purchaser { | ||
private final int price; |
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.
이거는 언제 쓰시는 거죠??
List<Lotto> lottos = new ArrayList<>(); | ||
int ticketCount = costToTicketNUM(); | ||
for (int i = 0; i < ticketCount; i++) { | ||
List<Integer> numbers = Randoms.pickUniqueNumbersInRange(1, 45, 6); |
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.
매직넘버 적용하면 좋겠네요
List<Integer> numbers = Randoms.pickUniqueNumbersInRange(1, 45, 6); | ||
lottos.add(new Lotto(numbers)); | ||
} | ||
this.lottos = lottos; |
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.
이 코드의 의미는 뭔가요??
|
||
|
||
|
||
|
||
|
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.
코드 컨벤션에 대해서 알아보세요!
lottos.add(new Lotto(numbers)); | ||
} | ||
this.lottos = lottos; | ||
List<List<Integer>> lottoList = new ArrayList<>(); |
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.
List가 아니라 List<List>로 하신 이유가 뭔가요??
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.
고생하셨습니다!
MVC 에 대해서 더 공부해보시면 좋을 것 같습니다.
AppConfig 적극 활용해주세요!
SIX, // 1등 | ||
FIVE_AND_BONUS, // 2등 | ||
FIVE, // 3등 | ||
FOUR, // 4등 | ||
THREE // 5등 | ||
// 꽝 |
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.
이렇게 하면 협업하는 입장에서 좋을지 생각해보셔야 할 것 같습니다ㅏ
try { | ||
View view = new View(); | ||
Contoller controller = new Contoller(view); | ||
controller.startController(); | ||
} catch (IllegalArgumentException e) { | ||
// 예외 발생 시 조용히 종료 - 추가 출력 없음 |
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.
AppConfig 사용해보세용
"AppConfig 순수자바" 키워드로 검색하신 후 공부하면 좋을 것 같아요
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.
컨트롤러가 너무 담당하는 일이 많고, 협력 객체를 직접 생성하고 있기 때문에 결합도가 너무 높습니다.
컨트롤러는 단순히 view와 model을 연결해 주는 곳이라고 생각하시면 됩니다. 유효성 검사가 컨트롤러에 있을 필요가 있을지 생각해 보시는게 좋을 것 같습니다!
AppConfig를 사용하셔서 담당하는 일을 줄이고, DI(생성자 주입)를 사용하셔보시기 바랍니다!
throw e; | ||
} | ||
} | ||
} No newline at end of file |
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.
|
||
|
||
public Map<Rank, Integer> calculateWinningStatistics() { | ||
Map<Rank, Integer> result = new EnumMap<>(Rank.class); |
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.
EnumMap을 쓰신 이유가 있으실까요?
private void validate(List<Integer> numbers) { | ||
if (numbers.size() != 6) { | ||
throw new IllegalArgumentException("로또 번호가 많거나 적음"); | ||
} | ||
|
||
if (numbers.size() != new HashSet<>(numbers).size()) { | ||
throw new IllegalArgumentException("로또 번호는 중복될 수 없습니다."); | ||
} | ||
} |
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.
에러 enum을 만드셨으니 이건 수정해주세요!
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class Lotto_purchaser { |
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.
카멜 케이스로 통일해주세요
|
||
// 구매 금액에 따른 로또 티켓 수 반환 | ||
public int costToTicketNUM() { | ||
return costOfPurchasing / 1000; |
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.
이것도 매직넘버 필요합니다!
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.
음 검증 전용으로 책임을 분리한건 좋습니다.
하지만 책임 분리가 곧 클래스를 무조건 나눈다는 뜻은 아닙니다.
이 점 생각하셔서 책임을 적절한 곳에 분배해 보세요!!
public void winningStatistics(Map<Rank, Integer> statistics, double lottoYield) { | ||
System.out.println("당첨 통계"); | ||
System.out.println("---"); | ||
|
||
System.out.println("3개 일치 (5,000원) - " + statistics.get(Rank.THREE) + "개"); | ||
System.out.println("4개 일치 (50,000원) - " + statistics.get(Rank.FOUR) + "개"); | ||
System.out.println("5개 일치 (1,500,000원) - " + statistics.get(Rank.FIVE) + "개"); | ||
System.out.println("5개 일치, 보너스 볼 일치 (30,000,000원) - " | ||
+ statistics.get(Rank.FIVE_AND_BONUS) + "개"); | ||
System.out.println("6개 일치 (2,000,000,000원) - " + statistics.get(Rank.SIX) + "개"); | ||
|
||
System.out.printf("총 수익률은 %.1f%%입니다.%n", lottoYield); | ||
} | ||
|
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.
view가 모델 내부를 알고있으면 안됩니다.
MVC 설계에서 View는 Model을 알면 안 되고, Model은 View를 알면 안 됩니다!
DTO를 활용해서 해보시는건 어떨까요??
No description provided.