-
Notifications
You must be signed in to change notification settings - Fork 26
2주차 미션 / 서버 3조 이윤희 #44
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?
Changes from all commits
adb3d07
7c31908
0b34dd5
73cb92a
8a8aa6a
5eb6c3d
779ace3
c5caa08
aff6206
beaf072
d0e6790
8fa2890
9b3a2d9
5ebaf3a
9f87691
0ea3ab6
7954a2b
449a429
3e5115e
79b8c4e
0ae857e
757d288
26aeaf4
5728800
b114c65
4adc205
468e5f8
6e4c4dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package ladder; | ||
|
|
||
| public enum Direction { | ||
|
|
||
| LEFT(-1), RIGHT(1), NONE(0); | ||
|
|
||
| private final int value; | ||
|
|
||
| Direction(int value) { | ||
| this.value = value; | ||
| } | ||
|
|
||
| public int getValue() { | ||
| return value; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package ladder; | ||
|
|
||
| public enum ExceptionMessage { | ||
|
|
||
| INVALID_LADDER_POSITION("사다리 위치는 0이상 입니다."), | ||
| INVALID_LADDER_NUMBER("사다리의 행과 열은 2 이상이어야 합니다."), | ||
| INVALID_POSITION("유효하지 않은 위치입니다."), | ||
| INVALID_DRAW_POSITION("사다리를 그릴 수 없는 위치입니다."), | ||
| INVALID_NATURAL_NUMBER("자연수가 아닙니다."); | ||
|
|
||
| private final String message; | ||
|
|
||
| ExceptionMessage(String message) { | ||
| this.message = message; | ||
| } | ||
|
|
||
| public String getMessage() { | ||
| return message; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package ladder; | ||
|
|
||
| public class GreaterThanOne { | ||
|
|
||
| private final int number; | ||
|
|
||
| public GreaterThanOne(int number) { | ||
| validate(number); | ||
| this.number = number; | ||
| } | ||
|
|
||
| public int getNumber() { | ||
| return number; | ||
| } | ||
|
|
||
| public static GreaterThanOne from(int number) { | ||
| return new GreaterThanOne(number); | ||
| } | ||
|
|
||
| private void validate(int number) { | ||
| if (!isGreaterThanOne(number)) { | ||
| throw new IllegalArgumentException(ExceptionMessage.INVALID_LADDER_NUMBER.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| private static boolean isGreaterThanOne(int number) { | ||
| return number > 1; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package ladder; | ||
|
|
||
| import ladder.creator.LadderCreator; | ||
| import ladder.creator.LadderManualCreator; | ||
| import ladder.creator.LadderRandomCreator; | ||
|
|
||
| public class LadderGame { | ||
|
|
||
| // LadderGame의 instance 변수로 LadderCreator 선언 | ||
| private final LadderCreator ladderCreator; | ||
|
|
||
| // LadderGame은 사다리를 직접 만들지 않고 LadderCreator에 의존 | ||
| // 외부에서 의존성 주입해준다 -> DI | ||
| public LadderGame(LadderCreator ladderCreator){ | ||
| this.ladderCreator = ladderCreator; | ||
| } | ||
|
|
||
| public LadderCreator getLadderCreator() { | ||
| return ladderCreator; | ||
| } | ||
|
|
||
| public int run(Position position) { | ||
| LadderRunner ladderRunner = new LadderRunner(ladderCreator.getRows()); | ||
| ladderRunner.run(position); | ||
| return position.getValue(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package ladder; | ||
|
|
||
| import ladder.creator.LadderManualCreator; | ||
| import ladder.creator.LadderRandomCreator; | ||
|
|
||
| // 정적 팩토리 매소드 패턴 | ||
| // 클라이언트 코드 (테스트 & 서비스 코드) 에서 직접 생성자를 호출하지 않도록 감싸줌 | ||
| // 외부에 의존성이 드러나지 않도록 하고 생성 책임을 Factory가 맡음 | ||
|
|
||
| public class LadderGameFactory { | ||
|
|
||
| public static LadderGame createRandomLadderGame(GreaterThanOne numberOfRow, GreaterThanOne numberOfPerson) { | ||
| LadderManualCreator manualCreator = new LadderManualCreator(numberOfRow, numberOfPerson); | ||
| return new LadderGame(new LadderRandomCreator(manualCreator, numberOfRow, numberOfPerson)); | ||
| } | ||
|
|
||
| public static LadderGame createManualLadderGame(GreaterThanOne numberOfRow, GreaterThanOne numberOfPerson) { | ||
| return new LadderGame(new LadderManualCreator(numberOfRow, numberOfPerson)); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package ladder; | ||
|
|
||
| public class LadderPosition { | ||
|
|
||
| Position row, column; | ||
|
|
||
| public LadderPosition(Position row, Position column) { | ||
| this.row = row; | ||
| this.column = column; | ||
| } | ||
|
|
||
| public Position getRow() { | ||
| return row; | ||
| } | ||
| public Position getColumn() { | ||
| return column; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package ladder; | ||
|
|
||
| public class LadderRunner { | ||
|
|
||
| private final Row[] rows; | ||
|
|
||
| public LadderRunner(Row[] rows) { | ||
| this.rows = rows; | ||
| } | ||
|
|
||
| // todo LadderPosition <- rowNumber + position | ||
| public void printRow(int rowNumber, int position, int currentRow) { | ||
| boolean isCurrent = (currentRow == rowNumber); | ||
| System.out.println(rows[rowNumber].rowToString(position, isCurrent)); | ||
| } | ||
|
Comment on lines
+12
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 별을 찍을지 제어변수로 결정하는 아이디어 괜찮은 것 같아요. 그런데 이런 제어결합도는 혼란을 야기할 수 있으니 주의해서 사용하는 게 좋을 것 같습니다. |
||
|
|
||
| public void printLadder(int row, int position){ | ||
| for (int i = 0; i < rows.length; i++) { | ||
| printRow(i, position, row); | ||
| } | ||
| System.out.println(); | ||
| } | ||
| public int run(Position position) { | ||
| for (int i = 0; i < rows.length; i++) { | ||
|
|
||
| System.out.println("Before"); | ||
| printLadder(i, position.getValue()); | ||
|
|
||
| rows[i].nextPosition(position); | ||
|
|
||
| System.out.println("After"); | ||
| printLadder(i, position.getValue()); | ||
| } | ||
| return position.getValue(); | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package ladder; | ||
|
|
||
| public class LadderSize { | ||
|
|
||
| private GreaterThanOne numberOfRow, numberOfPerson; | ||
|
|
||
| public LadderSize(GreaterThanOne numberOfRow, GreaterThanOne numberOfPerson) { | ||
| this.numberOfRow = numberOfRow; | ||
| this.numberOfPerson = numberOfPerson; | ||
| } | ||
|
|
||
| public int getNumberOfRandomLine() { | ||
| return (int)Math.round(this.numberOfRow.getNumber() * this.numberOfPerson.getNumber() * 0.3); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. int 형변환이나 round() 둘 중 하나만 써도 될 것 같네요! |
||
| } | ||
| } | ||
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.
인터페이스를 이용하니 아래와 같이 같은 기능을 하는 코드의 중복을 줄일 수 있었네요!