-
Notifications
You must be signed in to change notification settings - Fork 8
[로또 게임] 오형석 미션 제출합니다 #6
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
- return matched numbers with winning numbers
- print - input - critical logics
sunwootest
left a comment
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 class GameManager { | ||
|
|
||
| private NumberGame numberGame; | ||
|
|
||
| public GameManager(NumberGame chosenGame) { | ||
| this.numberGame = chosenGame; | ||
| } | ||
|
|
||
| public void playGame() { | ||
| numberGame.play(); | ||
| } | ||
| } |
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 double calculateEarningsRate() { | ||
| return ((double)prize / money) * 100; | ||
| } |
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.
money가 0임을 다른 곳에서 검증해주어도 예외가 아예 발생하지 않도록 0정도는 검증해주면 좋겠습니다.
협업과정에서 누가 코드를 건드릴 수도 있어서 최소한의 안전장치를 만들자는 것이고 이 또한 trade-off의 영역입니다. 과연 모든 메소드에서 validation 처리를 해야할까 고민해보세요!
| System.out.println("당첨 통계"); | ||
| System.out.println("---"); | ||
| System.out.println(String.format("3개 일치 (%s원) - %d개", decFormat.format(FIFTH.prize) ,resultNumber.get(MIN_RANK-1))); | ||
| System.out.println(String.format("4개 일치 (%s원) - %d개", decFormat.format(FOURTH.prize), resultNumber.get(MIN_RANK-2))); | ||
| System.out.println(String.format("5개 일치 (%s원) - %d개", decFormat.format(THIRD.prize), resultNumber.get(MIN_RANK-3))); | ||
| System.out.println(String.format("5개 일치 (%s원) - %d개", decFormat.format(SECOND.prize), resultNumber.get(MIN_RANK-4))); | ||
| System.out.println(String.format("6개 일치 (%s원) - %d개", decFormat.format(FIRST.prize), resultNumber.get(MIN_RANK-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.
한 번의 System 메소드 호출로 출력할 수 있도록 개선해보세요.
직접 실행하여 테스트 시 정상 동작하지만 Test를 돌리면 통과하지 못합니다
-> 문제를 파악해서 수정하겠습니다
NumberGame 인터페이스를 잘 짜서 추상화를 잘 하고 싶었으나 이것저것 수정하다보니 의도대로 되지 않았습니다.
Rule도 주입 하는 방식으로 하는 것이 좋지 않을까 생각했는데 시간이 부족해 구현하지 못했습니다
-> 리팩토링해서 보완하겠습니다
계속해서 리팩토링 하면서 테스트 코드도 만들어보겠습니다
간단한 흐름을 말씀드리자면
GameManager는 NumberGame을 implement하는 게임을 받아 실행하는 역할입니다
LottoGame classs는 전반적인 게임의 흐름을 관리합니다
Lotto class는 단 하나의 로또를 의미하며 구현 사항에 numbers를 private로 선언하라는 항목이 있어 당첨 번호와 비교하는 match 함수를 해당 class에 구현하였습니다
나머지는 각자의 이름대로의 기능을 가지는 class들입니다
열심히 리팩토링 해보겠습니다!