Skip to content
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

Open
wants to merge 7 commits into
base: baeksangha
Choose a base branch
from
53 changes: 0 additions & 53 deletions src/main/java/edu/nextstep/camp/carracing/CarRacing.java

This file was deleted.

18 changes: 0 additions & 18 deletions src/main/java/edu/nextstep/camp/carracing/CarValidator.java

This file was deleted.

27 changes: 0 additions & 27 deletions src/main/java/edu/nextstep/camp/carracing/ResultView.java

This file was deleted.

39 changes: 0 additions & 39 deletions src/main/java/edu/nextstep/camp/carracing/Winners.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
package edu.nextstep.camp.carracing;
package edu.nextstep.camp.carracing.domain;

public class Car {
private static final int MOVE_THRESHOLD = 4;
private static final String MOVE_SYMBOL = "-";

private final CarName name;
private int position;
private final Position position;

public Car(String name) {
this(name, 0);
this(name, new Position());
}

public Car(String name, int position) {
public Car(String name, Position position) {
this.name = new CarName(name);
this.position = position;
}

public void move(int number) {
if (number >= MOVE_THRESHOLD) {
position++;
this.position.increment();
}
}

public String getCurrentPositionString() {
return String.format("%s : %s", name.getName(), MOVE_SYMBOL.repeat(position));
return String.format("%s : %s", name.getName(), position.repeatSymbol(MOVE_SYMBOL));
}

public boolean isMaxPosition(int position) {
return this.position == position;
return this.position.isSame(position);
}

public CarName getName() {
return name;
public int getMaxValue(int value) {
return this.position.max(value);
}

public int getPosition() {
return position;
public CarName getName() {
return name;
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
package edu.nextstep.camp.carracing;
package edu.nextstep.camp.carracing.domain;

public class CarName {
private static final int MAX_LENGTH = 5;

private final String name;

public CarName(String name) {
validateCarName(name);
this.name = name;
}

private void validateCarName(String name) {
if (name == null || name.isBlank()) {
throw new IllegalArgumentException("์ž๋™์ฐจ ์ด๋ฆ„์€ null์ด๊ฑฐ๋‚˜ ๋นˆ ๋ฌธ์ž์—ด์ผ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.");
}
if (name.length() > MAX_LENGTH) {
throw new IllegalArgumentException("์ž๋™์ฐจ ์ด๋ฆ„์€ 5์ž๋ฅผ ์ดˆ๊ณผํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.");
}
this.name = name.trim();
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof CarName)) return false;
CarName other = (CarName) o;
return name.equals(other.name);
}

@Override
public int hashCode() {
return name.hashCode();
}

public String getName() {
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/edu/nextstep/camp/carracing/domain/CarRacing.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package edu.nextstep.camp.carracing.domain;

import edu.nextstep.camp.carracing.view.ResultView;

import java.util.List;

import static edu.nextstep.camp.carracing.view.InputView.getTryCount;
import static edu.nextstep.camp.carracing.view.InputView.inputCarNames;

public class CarRacing {

private CarRacing() {
throw new IllegalStateException("์ธ์Šคํ„ด์Šค ์ƒ์„ฑ์ด ๋ถˆ๊ฐ€๋Šฅํ•œ ํด๋ž˜์Šค์ž…๋‹ˆ๋‹ค.");
}

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());
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์‹คํ–‰์˜ ์ง„์ž…์ ์ธ main ๋ฉ”์†Œ๋“œ๊ฐ€ ๋„๋ฉ”์ธ ์˜์—ญ์— ์œ„์น˜ํ•˜๋Š” ๊ฒƒ์€ ์–ด์ƒ‰ํ•ด ๋ณด์—ฌ์š”
main์€ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์ตœ์ดˆ ์‹คํ–‰์ด ๋˜๋Š” ์˜์—ญ์ž…๋‹ˆ๋‹ค
image
์‹ค์ œ ๋กœ์ง์„ ์ˆ˜ํ–‰ํ•˜๋Š” ๋„๋ฉ”์ธ ๋ชจ๋ธ๊ณผ๋Š” ๋ถ„๋ฆฌ๋˜๋Š” ๊ฒƒ์ด ์ž์—ฐ์Šค๋Ÿฌ์›Œ ๋ณด์ด๋Š”๋ฐ,
๊ทธ๋ฆผ์—์„œ๋„ ๋„๋ฉ”์ธ ์˜์—ญ๋ณด๋‹ค๋Š” ์ปจํŠธ๋กค๋Ÿฌ ๊ณ„์ธต๊ณผ ๋” ๊ฐ€๊นŒ์šด ๋Š๋‚Œ์„ ์ค๋‹ˆ๋‹ค.

ํ•ด๋‹น ํด๋ž˜์Šค๋ฅผ ๋‹ค๋ฅธ ํŒจํ‚ค์ง€ ๊ณ„์ธต์œผ๋กœ ์ด๋™์‹œ์ผœ๋ณด๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค ๐Ÿš€

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8b55e9a
domain ๊ฐ์ฒด ์ƒ์œ„๋กœ ์ด๋™ํ•˜๊ณ , ํด๋ž˜์Šค๋ช…๋„ CarRacingApplication์œผ๋กœ ๋ณ€๊ฒฝํ–ˆ์Šต๋‹ˆ๋‹ค. ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

}
66 changes: 66 additions & 0 deletions src/main/java/edu/nextstep/camp/carracing/domain/Cars.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package edu.nextstep.camp.carracing.domain;

import edu.nextstep.camp.carracing.view.ResultView;

import java.util.ArrayList;
import java.util.List;

import static edu.nextstep.camp.carracing.util.RandomNumberGenerator.generateRandomNumber;

public class Cars {
private final List<Car> values;

public Cars(List<Car> cars) {
this.values = cars;
}

public static Cars fromNames(List<String> carNames) {
List<Car> cars = new ArrayList<>();
Comment on lines +16 to +17
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ •์  ํŒฉํ† ๋ฆฌ ๋ฉ”์†Œ๋“œ๋กœ ๊ฐ„๊ฒฐํ•˜๊ฒŒ ํ‘œํ˜„์ด ๊ฐ€๋Šฅํ•˜๋„ค์š”! ๐Ÿ‘ ๐Ÿ‘

for (String carName : carNames) {
cars.add(new Car(carName));
}
return new Cars(cars);
}

public void moveCars() {
for (Car car : this.values) {
car.move(generateRandomNumber());
}
}
Comment on lines +24 to +28
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Car์˜ ์›€์ง์ž„์€ ํ…Œ์ŠคํŠธํ•˜๊ธฐ ์‰ฝ๊ฒŒ ๋งŒ๋“ค์–ด์กŒ์ง€๋งŒ
Cars์˜ moveCars๋Š” ๋žœ๋ค์„ ๋‚ด๋ถ€์ ์œผ๋กœ ์ƒ์„ฑํ•˜๊ณ  ์žˆ์–ด ํ…Œ์ŠคํŠธํ•  ๋•Œ ์ œ์–ดํ•˜๊ธฐ๊ฐ€ ํž˜๋“ค ๊ฒƒ ๊ฐ™์•„์š”

Cars๋„ ๋„๋ฉ”์ธ ๋ชจ๋ธ์ด๋‹ˆ ํ…Œ์ŠคํŠธํ•˜๊ธฐ ์‰ฌ์šด ๊ตฌ์กฐ๋กœ ์žฌ๊ตฌ์„ฑํ•˜๋ฉด ์–ด๋–จ๊นŒ์š”?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์š”๊ฑฐ ์–ด๋–ป๊ฒŒ ํ•˜๋ฉด ํ…Œ์ŠคํŠธํ•˜๊ธฐ ์‰ฌ์šด ๊ตฌ์กฐ๋กœ ์žฌ๊ตฌ์„ฑํ•  ์ˆ˜ ์žˆ์„๊นŒ์š”? ์ข€ ๊ณ ๋ฏผํ•ด๋ณด์•˜๋Š”๋ฐ ๊ตฌ์กฐ๊ฐ€ ์•ˆ๋– ์˜ค๋ฆ…๋‹ˆ๋‹ค ๐Ÿ™†โ€โ™‚๏ธ

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Car์˜ move๋Š” ์ˆซ์ž๋ฅผ ์ง์ ‘ ๋„ฃ๋Š” ๋ฐฉ์‹์œผ๋กœ ๋žœ๋ค์„ ์ œ์–ดํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋งŒ๋“ค์–ด ๋ณด์‹  ๊ฒƒ ๊ฐ™์•„์š”
๊ฐ™์€ ๋งฅ๋ฝ์œผ๋กœ Cars์—๋„ ๋™์ผํ•˜๊ฒŒ ๋žœ๋ค์„ ์ƒ์„ฑํ•˜๋Š” ๋žœ๋ค์ƒ์„ฑ๊ธฐ๋ฅผ ์ „๋‹ฌํ•ด ๋ณด๋ฉด ์–ด๋–จ๊นŒ์š”?

cars.moveCars(NumberGenerator generator) {
    ...
    car.move(generator.random());
}

NumberGenerator๋ฅผ ์ธํ„ฐํŽ˜์ด์Šคํ™” ์‹œํ‚ค๊ณ  ํ”„๋กœ๋•์…˜ ์ฝ”๋“œ์—๋Š” ๋žœ๋ค๋ฒˆํ˜ธ ์ƒ์„ฑ๊ธฐ ๊ตฌํ˜„์ฒด๋ฅผ,
ํ…Œ์ŠคํŠธ ์ฝ”๋“œ์—๋Š” ๊ณ ์ •๋ฒˆํ˜ธ ์ƒ์„ฑ๊ธฐ ๊ตฌํ˜„์ฒด๋กœ ํ…Œ์ŠคํŠธํ•ด๋ณผ ์ˆ˜ ์žˆ์ง€ ์•Š์„๊นŒ์š”?

์ด ๋ฐฉ์‹์ด ๊ผญ ์•„๋‹ˆ๋”๋ผ๋„ ๋ฐฉ๋ฒ•์€ ๋งค์šฐ ๋งŽ์Šต๋‹ˆ๋‹ค.
๊ด€๋ จํ•ด์„œ ์ „๋žต ํŒจํ„ด์— ๋Œ€ํ•ด ๊ฒ€์ƒ‰ํ•ด ๋ณด์‹œ๋ฉด ์ข‹์€ ๊ธ€๋“ค์ด ๋งŽ์ด ๋‚˜์˜ฌ๊ฑฐ์˜ˆ์š”!


public void printCarStatus() {
for (Car car : this.values) {
ResultView.printCarStatus(car);
}
ResultView.printLine();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋„๋ฉ”์ธ ๋ชจ๋ธ์ด View๋ฅผ ์˜์กดํ•˜๊ณ  ์žˆ๋„ค์š”!

ํ•ต์‹ฌ ๋น„์ง€๋‹ˆ์Šค ๋กœ์ง์„ ๊ฐ€์ง€๋Š” ๊ฐ์ฒด๋ฅผ domain ํŒจํ‚ค์ง€, UI ๊ด€๋ จํ•œ ๊ฐ์ฒด๋ฅผ view ํŒจํ‚ค์ง€์— ๊ตฌํ˜„ํ•œ๋‹ค.
MVC ํŒจํ„ด ๊ธฐ๋ฐ˜์œผ๋กœ ๋ฆฌํŒฉํ† ๋งํ•ด view ํŒจํ‚ค์ง€์˜ ๊ฐ์ฒด๊ฐ€ domain ํŒจํ‚ค์ง€ ๊ฐ์ฒด์— ์˜์กดํ•  ์ˆ˜ ์žˆ์ง€๋งŒ, domain ํŒจํ‚ค์ง€์˜ ๊ฐ์ฒด๋Š” view ํŒจํ‚ค์ง€ ๊ฐ์ฒด์— ์˜์กดํ•˜์ง€ ์•Š๋„๋ก ๊ตฌํ˜„ํ•œ๋‹ค.

์š”๊ตฌ์‚ฌํ•ญ์— ๋”ฐ๋ผ ๋ฆฌํŒฉํ† ๋ง ํ•ด๋ณด๋ฉด ์ข‹๊ฒ ์Šต๋‹ˆ๋‹ค!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์š”๊ฑฐ ํฌํ•จํ•œ ๋ฆฌํŒฉํ† ๋ง ์ปค๋ฐ‹์ž…๋‹ˆ๋‹ค. 2908754


public int getMaxPosition() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getMaxPosition()์„ ์™ธ๋ถ€๋กœ ๋…ธ์ถœ์‹œํ‚ฌ ํ•„์š”๊ฐ€ ์žˆ์„๊นŒ์š”?

int maxPosition = 0;
for (Car car : this.values) {
maxPosition = car.getMaxValue(maxPosition);
}
return maxPosition;
}

public Cars getWinners() {
int winnerPosition = getMaxPosition();
List<String> result = new ArrayList<>();
for (Car car : this.values) {
if (car.isMaxPosition(winnerPosition)) {
result.add(car.getName().getName());
}
}
Copy link
Member

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๋ฅผ ์ค„์—ฌ๋ณด๋ฉด ์ข‹๊ฒ ์Šต๋‹ˆ๋‹ค.
์š”๊ตฌ์‚ฌํ•ญ์ด๋‹ˆ ๋ฆฌํŒฉํ† ๋ง ํ•ด๋ณด์‹œ์ฃ !

return Cars.fromNames(result);
}

public List<String> getWinnerNames() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getWinners() ๋ฉ”์†Œ๋“œ๋ฅผ ์ œ๊ณตํ•˜๊ณ  ์žˆ์œผ๋‹ˆ ์ด๋ฆ„๋งŒ์„ ์ถ”์ถœํ•˜๋Š” ๊ฒƒ์€
ํด๋ผ์ด์–ธํŠธ ์ฝ”๋“œ์—์„œ๋„ ์ถฉ๋ถ„ํžˆ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋Šฅ ๊ฐ™์Šต๋‹ˆ๋‹ค!

๋˜ํ•œ ์ถœ๋ ฅ์„ ์œ„ํ•œ ๊ธฐ๋Šฅ์ธ ๊ฒƒ ๊ฐ™๊ธฐ๋„ํ•˜๋„ค์š”

List<String> result = new ArrayList<>();
for (Car value : this.values) {
if (value.isMaxPosition(getMaxPosition())) {
result.add(value.getName().getName());
}
}
return result;
}
}
32 changes: 32 additions & 0 deletions src/main/java/edu/nextstep/camp/carracing/domain/Position.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package edu.nextstep.camp.carracing.domain;

public class Position {
Copy link
Member

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

๊ฐ’์€ ๊ฐ™์•„๋ณด์ด๋Š”๋ฐ ์™œ ๋‹ค๋ฅด๋‹ค๊ณ  ๋‚˜์˜ฌ๊นŒ์š”?
๋™๋“ฑ์„ฑ์„ ๋ณด์žฅ์‹œ์ผœ ๋ณด๋ฉด ์ข‹๊ฒ ์Šต๋‹ˆ๋‹ค!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋ชจ๋“  ๋กœ์ง์— ๋‹จ์œ„ ํ…Œ์ŠคํŠธ๋ฅผ ๊ตฌํ˜„ํ•œ๋‹ค

์œ„ ์ฝ”๋ฉ˜ํŠธ ์ฐธ๊ณ ํ•ด์„œ ํ…Œ์ŠคํŠธ๋„ ๊ฐ™์ด ์ž‘์„ฑํ•ด ๋ณด๋ฉด ์ข‹๊ฒ ์Šต๋‹ˆ๋‹ค!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bb17bfe
๋™๋“ฑ์„ฑ ๋ณด์žฅ์„ ์œ„ํ•ด equals์™€ hashcode ๋ฉ”์„œ๋“œ ์˜ค๋ฒ„๋ผ์ด๋”ฉํ•ด์ฃผ๊ณ , ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋„ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค. ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!

private int value;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์–‘์ˆ˜๋ฅผ ํ‘œํ˜„ํ•˜๋Š” ๊ฐ’ ๊ฐ์ฒด ์ข‹์Šต๋‹ˆ๋‹ค ๐Ÿ‘


public Position() {
this(0);
}

public Position(int value) {
if (value < 0) {
throw new IllegalArgumentException("์œ„์น˜ ๊ฐ’์— ์Œ์ˆ˜๊ฐ€ ๋“ค์–ด๊ฐˆ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.");
}
this.value = value;
}

public void increment() {
this.value++;
}
Copy link
Member

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/

๊ด€๋ จํ•ด์„œ ์ฝ์–ด๋ณด์‹œ๋ฉด ๋„์›€์ด ๋ ๊ฑฐ์˜ˆ์š”

Copy link
Author

@baeksangha baeksangha Mar 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ํฌ๋น„๋‹˜ ๋ผ์ด๋ธŒ ๊ฐ•์˜์—์„œ ์ œ๊ฐ€ ํ•œ๊ฒƒ์ฒ˜๋Ÿผ ํ‘œํ˜„ํ•˜์‹œ๊ธธ๋ž˜ ๋”ฐ๋ผ ์“ฐ๊ธด ํ–ˆ๋Š”๋ฐ, ๊ฐ์ฒด์˜ ๊ฐ€๋ณ€์„ฑvs๋ถˆ๋ณ€์„ฑ ์ธก๋ฉด์—์„œ ๋ถˆ๋ณ€์„ฑ์„ ๊ฐ€์ง„ ๊ฐ์ฒด๋Š” ๊ทธ๋งŒํผ ์ธ์Šคํ„ด์Šค๊ฐ€ ๋งŽ์ด ์ƒ์„ฑ๋˜๋‹ˆ ๊ฐ์ฒด ์ƒ์„ฑ ๋น„์šฉ์ด๋‚˜ GC์— ๋ถ€๋‹ด์ด ์žˆ์„ ์ˆ˜ ์žˆ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ์Šต๋‹ˆ๋‹ค.
๊ณต์œ  ์ฃผ์‹  ๋ฌธ์„œ๋ฅผ ์ฝ์–ด๋ณด๋‹ˆ VO ๊ฐ์ฒด๋Š” ๋ถˆ๋ณ€์„ฑ์ด ๋ณด์žฅ๋˜์–ด์•ผ ํ•˜๋Š” ๊ฒƒ์ด ๋งž๋Š” ๊ฒƒ ๊ฐ™๋„ค์š”. ์ฝ์–ด๋ณด๊ณ  ์ฝ”๋“œ ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค. adb180a ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ์•ž์œผ๋กœ๋„ ์ด๋Ÿฌํ•œ ์ƒํ™ฉ์„ ๋งž๋‹ฅ๋œจ๋ฆฐ๋‹ค๋ฉด ๊ฐ์ฒด ์ƒ์„ฑ ๋น„์šฉ์€ ๋ฌด์‹œํ•  ์ˆ˜ ์žˆ๋‹ค๊ณ  ๋ณด๊ณ (์•„๋ฌด๋ž˜๋„ ํด๋ž˜์Šค์—์„œ ๊ฐ์ฒด๋ฅผ ๋ฌดํ•œํžˆ ๋งŽ์ด ์ƒ์„ฑํ•˜์ง„ ์•Š์œผ๋‹ˆ..) ๋ถˆ๋ณ€์„ฑ์„ ๋ณด์žฅํ•˜๋„๋ก ๊ฐ์ฒด๋ฅผ ์„ค๊ณ„ํ•˜๋Š”๊ฒŒ ๋‚˜์„๊นŒ์š”?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ €๋„ ๊ฐ™์€ ๊ณ ๋ฏผ์„ ํ–ˆ์—ˆ๋Š”๋ฐ์š”
GC์—์„œ ๊ธˆ๋ฐฉ ์ฒ˜๋ฆฌํ•ด์ฃผ๊ธฐ ๋•Œ๋ฌธ์— ๋น„์šฉ์ด ๊ทธ๋ ‡๊ฒŒ ํฌ์ง€๋Š” ์•Š์Šต๋‹ˆ๋‹ค. ์š”์ฆ˜ ์ธ์Šคํ„ด์Šค๋„ ๋นต๋นตํ•ด์„œ์š” ใ…Žใ…Ž
์„ฑ๋Šฅ ๋ฌธ์ œ๋ผํ•˜๋ฉด ์ฃผ๋กœ ๋„คํŠธ์›Œํฌ, ๋ณต์žกํ•œ CPU ์—ฐ์‚ฐ, DB์—์„œ ๋ฐœ์ƒํ•˜๊ธฐ ๋•Œ๋ฌธ์— ํฌ๊ฒŒ ๊ฑฑ์ •์€ ์•ˆํ•ด๋„ ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
์„ฑ๋Šฅ ๋ฌธ์ œ๊ฐ€ ์žˆ๋‹ค๊ณ  ํ•˜๋”๋ผ๋„
๊ฐ’ ๊ฐ์ฒด๋งŒ์˜ ํ‘œํ˜„๋ ฅ์ด๋ผ๋˜์ง€ ๋ถˆ๋ณ€์„ฑ์—์„œ ์–ป๋Š” ์žฅ์ ์ด ๋” ํฌ๋‹ค๊ณ  ์ƒ๊ฐํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ €๋Š” ๊ทธ๋ž˜๋„ ์‚ฌ์šฉํ•˜๋Š” ํŽธ์ž…๋‹ˆ๋‹ค.


public boolean isSame(int number) {
return this.value == number;
}

public String repeatSymbol(String symbol) {
return symbol.repeat(value);
}
Copy link
Member

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 ๊ฐ์ฒด๋ฅผ ์ง์ ‘์ ์œผ๋กœ ์˜์กดํ•˜์ง€๋Š” ์•Š์ง€๋งŒ ์ถœ๋ ฅ์„ ์œ„ํ•œ ๋ฉ”์†Œ๋“œ๋„ค์š”
์ด๋Ÿฌํ•œ ๊ฐ„์ ‘์ ์ธ ์˜์กด๋„ ์ œ๊ฑฐํ•˜๋ฉด ์ข‹๊ฒ ์Šต๋‹ˆ๋‹ค!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c871377 ์š”๋Ÿฐ ์‹์œผ๋กœ ์ˆ˜์ •ํ•ด ๋ณด์•˜์Šต๋‹ˆ๋‹ค.


public int max(int number) {
return Math.max(this.value, number);
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package edu.nextstep.camp.carracing;
package edu.nextstep.camp.carracing.util;

import java.util.Random;

public class RandomNumberGenerator {
private static final int DEFAULT_BOUND = 10;
private static final Random random = new Random();

private RandomNumberGenerator() {
throw new IllegalStateException("์ธ์Šคํ„ด์Šค ์ƒ์„ฑ์ด ๋ถˆ๊ฐ€๋Šฅํ•œ ํด๋ž˜์Šค์ž…๋‹ˆ๋‹ค.");
}

public static int generateRandomNumber(int bound) {
return random.nextInt(bound);
public static int generateRandomNumber() {
return random.nextInt(DEFAULT_BOUND);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package edu.nextstep.camp.carracing;
package edu.nextstep.camp.carracing.view;

import java.util.List;
import java.util.Scanner;
Expand Down
Loading