-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
๐ 5๋จ๊ณ - ์๋์ฐจ ๊ฒฝ์ฃผ(๋ฆฌํฉํ ๋ง) #6078
base: baeksangha
Are you sure you want to change the base?
Conversation
์๋์ฐจ์ ์ด๋ฆ์ ๋ทฐ์๊ฒ๋ก๋ง ์ ์ ๋ฌํ ์ ์๋ค๋ฉด CarName ๊ฐ์ฒด ๋๋ String์ ๋๊ฒจ์ค๋ ํฐ ์๊ด์ ์๋ค๊ณ ์๊ฐํฉ๋๋ค. |
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 Position { | ||
private int value; |
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 increment() { | ||
this.value++; | ||
} |
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.
๊ฐ ๊ฐ์ฒด๋ฅผ ๋ถ๋ณ์ผ๋ก ๋ง๋ค์ด๋ณด๋ ๊ฒ์ ์ด๋จ๊น์?
increment()
๋ฉ์๋๋ ๊ฐ์ฒด์ ๋ด๋ถ ์ํ๋ฅผ ๋ณ๊ฒฝํ๋ ๊ฐ๋ณ๋ฐฉ์์ผ๋ก ๋์ํ๊ณ ์์ต๋๋ค
๊ฐ ๊ฐ์ฒด๋ ๋ถ๋ณ์ฑ์ ๊ฐ์ง๊ฒ ์ค๊ณํ๋ ๊ฒ์ด ์ข์๋ฐ์
๊ธฐ์กด ๊ฐ ์์ฒด๊ฐ ๋ณํ๊ธฐ๋ณด๋ค๋ ์๋ก์ด ๊ฐ์ ๋ง๋ค์ด๋ด๋ ๋ฐฉ์์ด ๋ ์ ์ ํ ๊ฒ ๊ฐ์์
์๋ฅผ ๋ค์ด, 1 + 1 = 2์์ ๊ธฐ์กด์ 1(๊ฐ)์ด 2๋ก ๋ณํ๋ ๊ฒ์ด ์๋๋ผ, ์๋ก์ด 2(๊ฐ)๊ฐ ์์ฑ๋๋ ๊ฒ์ฒ๋ผ์!
var newPosition = position.increment();
์ด๋ ๊ฒ ํ๋ฉด ๋ถ๋ณ์ฑ์ ์ ์งํ ์ ์๊ณ , ๊ฐ์ฒด์ ์์์น ๋ชปํ ๋ณ๊ฒฝ์ ๋ฐฉ์งํ ์ ์์ต๋๋ค! ๐
https://tecoble.techcourse.co.kr/post/2021-05-16-dto-vs-vo-vs-entity/
๊ด๋ จํด์ ์ฝ์ด๋ณด์๋ฉด ๋์์ด ๋ ๊ฑฐ์์
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.
ํฌ๋น๋ ๋ผ์ด๋ธ ๊ฐ์์์ ์ ๊ฐ ํ๊ฒ์ฒ๋ผ ํํํ์๊ธธ๋ ๋ฐ๋ผ ์ฐ๊ธด ํ๋๋ฐ, ๊ฐ์ฒด์ ๊ฐ๋ณ์ฑvs๋ถ๋ณ์ฑ ์ธก๋ฉด์์ ๋ถ๋ณ์ฑ์ ๊ฐ์ง ๊ฐ์ฒด๋ ๊ทธ๋งํผ ์ธ์คํด์ค๊ฐ ๋ง์ด ์์ฑ๋๋ ๊ฐ์ฒด ์์ฑ ๋น์ฉ์ด๋ GC์ ๋ถ๋ด์ด ์์ ์ ์๋ค๊ณ ์๊ฐํ์ต๋๋ค.
๊ณต์ ์ฃผ์ ๋ฌธ์๋ฅผ ์ฝ์ด๋ณด๋ VO ๊ฐ์ฒด๋ ๋ถ๋ณ์ฑ์ด ๋ณด์ฅ๋์ด์ผ ํ๋ ๊ฒ์ด ๋ง๋ ๊ฒ ๊ฐ๋ค์. ์ฝ์ด๋ณด๊ณ ์ฝ๋ ์์ ํ์ต๋๋ค. adb180a ๊ฐ์ฌํฉ๋๋ค. ์์ผ๋ก๋ ์ด๋ฌํ ์ํฉ์ ๋ง๋ฅ๋จ๋ฆฐ๋ค๋ฉด ๊ฐ์ฒด ์์ฑ ๋น์ฉ์ ๋ฌด์ํ ์ ์๋ค๊ณ ๋ณด๊ณ (์๋ฌด๋๋ ํด๋์ค์์ ๊ฐ์ฒด๋ฅผ ๋ฌดํํ ๋ง์ด ์์ฑํ์ง ์์ผ๋..) ๋ถ๋ณ์ฑ์ ๋ณด์ฅํ๋๋ก ๊ฐ์ฒด๋ฅผ ์ค๊ณํ๋๊ฒ ๋์๊น์?
public String repeatSymbol(String symbol) { | ||
return symbol.repeat(value); | ||
} |
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 ํจํด ๊ธฐ๋ฐ์ผ๋ก ๋ฆฌํฉํ ๋งํด view ํจํค์ง์ ๊ฐ์ฒด๊ฐ domain ํจํค์ง ๊ฐ์ฒด์ ์์กดํ ์ ์์ง๋ง, domain ํจํค์ง์ ๊ฐ์ฒด๋ view ํจํค์ง ๊ฐ์ฒด์ ์์กดํ์ง ์๋๋ก ๊ตฌํํ๋ค.
view ๊ฐ์ฒด๋ฅผ ์ง์ ์ ์ผ๋ก ์์กดํ์ง๋ ์์ง๋ง ์ถ๋ ฅ์ ์ํ ๋ฉ์๋๋ค์
์ด๋ฌํ ๊ฐ์ ์ ์ธ ์์กด๋ ์ ๊ฑฐํ๋ฉด ์ข๊ฒ ์ต๋๋ค!
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.
c871377 ์๋ฐ ์์ผ๋ก ์์ ํด ๋ณด์์ต๋๋ค.
@@ -0,0 +1,32 @@ | |||
package edu.nextstep.camp.carracing.domain; | |||
|
|||
public class Position { |
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.
var position1 = new Position(5);
var position2 = new Position(5);
position1.equals(position2); // false
๊ฐ์ ๊ฐ์๋ณด์ด๋๋ฐ ์ ๋ค๋ฅด๋ค๊ณ ๋์ฌ๊น์?
๋๋ฑ์ฑ์ ๋ณด์ฅ์์ผ ๋ณด๋ฉด ์ข๊ฒ ์ต๋๋ค!
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.
bb17bfe
๋๋ฑ์ฑ ๋ณด์ฅ์ ์ํด equals์ hashcode ๋ฉ์๋ ์ค๋ฒ๋ผ์ด๋ฉํด์ฃผ๊ณ , ํ
์คํธ ์ฝ๋๋ ์ถ๊ฐํ์ต๋๋ค. ๊ฐ์ฌํฉ๋๋ค!
} | ||
|
||
public static void printResultMessage() { | ||
System.out.println('\n' + RESULT_MESSAGE); |
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.out.println('\n' + RESULT_MESSAGE); | |
System.out.println(System.lineSeparator() + RESULT_MESSAGE); |
OS ํ๊ฒฝ์ ๋ฐ๋ผ ๊ฐํ ๋ฌธ์๊ฐ ๋ค๋ฅด๋ฏ๋ก, ํ๋์ฝ๋ฉ๋ \n
๋์
lineSeparator()
๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ด ์ข๊ฒ ์ต๋๋ค!
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.lineSeperator()
๋ฅผ ์ฌ์ฉํ๋ ๋ฐฉ์์ผ๋ก ๋ณ๊ฒฝํ์ต๋๋ค. ๋ชฐ๋๋ ์ฌ์ค์ด๋ค์
for (Car car : this.values) { | ||
if (car.isMaxPosition(winnerPosition)) { | ||
result.add(car.getName().getName()); | ||
} | ||
} |
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.
indent(์ธ๋ดํธ, ๋ค์ฌ์ฐ๊ธฐ) depth๋ฅผ 2๋ฅผ ๋์ง ์๋๋ก ๊ตฌํํ๋ค. 1๊น์ง๋ง ํ์ฉํ๋ค.
์๋ฅผ ๋ค์ด while๋ฌธ ์์ if๋ฌธ์ด ์์ผ๋ฉด ๋ค์ฌ์ฐ๊ธฐ๋ 2์ด๋ค.
ํํธ: indent(์ธ๋ดํธ, ๋ค์ฌ์ฐ๊ธฐ) depth๋ฅผ ์ค์ด๋ ์ข์ ๋ฐฉ๋ฒ์ ํจ์(๋๋ ๋ฉ์๋)๋ฅผ ๋ถ๋ฆฌํ๋ฉด ๋๋ค.
๋ฉ์๋๋ฅผ ์ถ์ถํ๋ฉด์ depth๋ฅผ ์ค์ฌ๋ณด๋ฉด ์ข๊ฒ ์ต๋๋ค.
์๊ตฌ์ฌํญ์ด๋ ๋ฆฌํฉํ ๋ง ํด๋ณด์์ฃ !
} | ||
|
||
public static void printWinners(Cars winners) { | ||
System.out.println(String.join(", ", winners.getWinnerNames()) + "๊ฐ ์ต์ข ์ฐ์นํ์ต๋๋ค."); |
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.
join ์ฌ์ฉ์ผ๋ก ๊น๋ํ๋ค์! ๐ฏ
public static void main(String[] args) { | ||
List<String> carNames = inputCarNames(); | ||
int tryCount = getTryCount(); | ||
|
||
Cars cars = Cars.fromNames(carNames); | ||
|
||
ResultView.printResultMessage(); | ||
for (int i = 0; i < tryCount; i++) { | ||
cars.moveCars(); | ||
cars.printCarStatus(); | ||
} | ||
ResultView.printWinners(cars.getWinners()); | ||
} |
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.
์ ํ๋ฆฌ์ผ์ด์
์คํ์ ์ง์
์ ์ธ main
๋ฉ์๋๊ฐ ๋๋ฉ์ธ ์์ญ์ ์์นํ๋ ๊ฒ์ ์ด์ํด ๋ณด์ฌ์
main
์ ์ ํ๋ฆฌ์ผ์ด์
์ ์ต์ด ์คํ์ด ๋๋ ์์ญ์
๋๋ค
์ค์ ๋ก์ง์ ์ํํ๋ ๋๋ฉ์ธ ๋ชจ๋ธ๊ณผ๋ ๋ถ๋ฆฌ๋๋ ๊ฒ์ด ์์ฐ์ค๋ฌ์ ๋ณด์ด๋๋ฐ,
๊ทธ๋ฆผ์์๋ ๋๋ฉ์ธ ์์ญ๋ณด๋ค๋ ์ปจํธ๋กค๋ฌ ๊ณ์ธต๊ณผ ๋ ๊ฐ๊น์ด ๋๋์ ์ค๋๋ค.
ํด๋น ํด๋์ค๋ฅผ ๋ค๋ฅธ ํจํค์ง ๊ณ์ธต์ผ๋ก ์ด๋์์ผ๋ณด๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค ๐
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.
8b55e9a
domain ๊ฐ์ฒด ์์๋ก ์ด๋ํ๊ณ , ํด๋์ค๋ช
๋ CarRacingApplication์ผ๋ก ๋ณ๊ฒฝํ์ต๋๋ค. ๊ฐ์ฌํฉ๋๋ค.
public static Cars fromNames(List<String> carNames) { | ||
List<Car> cars = 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.
์ ์ ํฉํ ๋ฆฌ ๋ฉ์๋๋ก ๊ฐ๊ฒฐํ๊ฒ ํํ์ด ๊ฐ๋ฅํ๋ค์! ๐ ๐
public void moveCars() { | ||
for (Car car : this.values) { | ||
car.move(generateRandomNumber()); | ||
} | ||
} |
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.
Car์ ์์ง์์ ํ
์คํธํ๊ธฐ ์ฝ๊ฒ ๋ง๋ค์ด์ก์ง๋ง
Cars์ moveCars
๋ ๋๋ค์ ๋ด๋ถ์ ์ผ๋ก ์์ฑํ๊ณ ์์ด ํ
์คํธํ ๋ ์ ์ดํ๊ธฐ๊ฐ ํ๋ค ๊ฒ ๊ฐ์์
Cars๋ ๋๋ฉ์ธ ๋ชจ๋ธ์ด๋ ํ ์คํธํ๊ธฐ ์ฌ์ด ๊ตฌ์กฐ๋ก ์ฌ๊ตฌ์ฑํ๋ฉด ์ด๋จ๊น์?
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.
์๊ฑฐ ์ด๋ป๊ฒ ํ๋ฉด ํ ์คํธํ๊ธฐ ์ฌ์ด ๊ตฌ์กฐ๋ก ์ฌ๊ตฌ์ฑํ ์ ์์๊น์? ์ข ๊ณ ๋ฏผํด๋ณด์๋๋ฐ ๊ตฌ์กฐ๊ฐ ์๋ ์ค๋ฆ ๋๋ค ๐โโ๏ธ
5๋จ๊ณ ๋ฆฌํฉํ ๋ง ์๊ตฌ์ฌํญ
์์ ๋ด์ฉ
๊ถ๊ธํ ์
4๋จ๊ณ ํผ๋๋ฐฑ์์ getWinners์ ์๋ต ํด๋์ค์ผ๋ก winner ํด๋์ค๋ฅผ ์์ฑํ๋ ๊ฒ์ ๋ง์ํด์ฃผ์ จ๋๋ฐ, ๊ตฌ์ฑ์ ์ด๋ป๊ฒ ํ ์ง ๊ณ ๋ฏผ๋์ต๋๋ค.
Winner ํด๋์ค๋ฅผ ๊ตฌ์ฑํ๊ณ Car ๊ฐ์ฒด๋ฅผ ๋ฐ์ผ๋ฉด Winner์์ ์๋์ฐจ์ ์ด๋ฆ์ ์ป๊ธฐ ์ํด์
car.getName().getName();
์ ๋ฐ๋ ํ์์ผ๋ก ๊ตฌํํ๋๊ฑด๊ฐ์? Winner ํด๋์ค์ ์์๊ฐ๊ณผ ๋ฌธ์์ด ํํ์ ํ๋๊ฐ ๋ค์ด๊ฐ์ผ ํ ์ง, ํด๋์ค๋ก ํฌ์ฅ๋ ํ๋๋ค์ด ๋ค์ด๊ฐ์ผ ํ ์ง ๊ณ ๋ฏผ๋์ด์ ์ง๋ฌธ๋๋ฆฝ๋๋ค!