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๋‹จ๊ณ„ - ์ž๋™์ฐจ ๊ฒฝ์ฃผ(๋ฆฌํŒฉํ† ๋ง) #5818

Open
wants to merge 32 commits into
base: jonghyeonleee
Choose a base branch
from

Conversation

jonghyeonLeee
Copy link

์•ˆ๋…•ํ•˜์„ธ์š”!

5๋‹จ๊ณ„๋ฅผ ์ง„ํ–‰ํ–ˆ์Šต๋‹ˆ๋‹ค.

์ธํ„ฐํŽ˜์ด์Šค๋กœ ๋ถ„๋ฆฌํ•˜๋Š” ๋ถ€๋ถ„์ด ๊ณ„์†.. ์ดํ•ด๊ฐ€ ์•ˆ๋์ง€๋งŒ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๋ฐ›๋Š” ๋ฐฉํ–ฅ์œผ๋กœ ์ง„ํ–‰ํ•ด๋ดค์Šต๋‹ˆ๋‹ค!!

4๋‹จ๊ณ„ ํ”ผ๋“œ๋ฐฑ ์ ์šฉ ํ•˜์˜€์œผ๋ฉฐ,
MVC ๋ถ„๋ฆฌ, ํ”„๋ฆฌ๋ฏธํ‹ฐ๋ธŒ ํƒ€์ž…์„ ํด๋ž˜์Šค๋กœ ๊ตฌํ˜„, model์—์„  view์™€ controller๋ฅผ ์ƒ์† ๋ฐ›์ง€ ์•Š๋„๋ก ์ตœ๋Œ€ํ•œ ๋ถ„๋ฆฌํ•ด๋ดค์Šต๋‹ˆ๋‹ค!!

ํ”ผ๋“œ๋ฐฑ ์ฃผ์‹œ๋ฉด ๋ฐ˜์˜ํ•˜๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค!

๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค~ :)

jonghyeon added 24 commits October 15, 2024 19:32
Copy link
Member

@dhmin5693 dhmin5693 left a comment

Choose a reason for hiding this comment

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

์•ˆ๋…•ํ•˜์„ธ์š”.

์ด๋ฒˆ ๊ณผ์ œ๋ฅผ ์ง„ํ–‰ํ•˜๋ฉด์„œ ๊ณ ๋ฏผ์„ ๋˜๊ฒŒ ๋งŽ์ด ํ•˜์‹  ๊ฒƒ ๊ฐ™์•„์š”.
์–ด๋ ค์šด ์  ์žˆ์œผ์‹œ๋ฉด ์–ธ์ œ๋“ ์ง€ DM์œผ๋กœ ์งˆ๋ฌธํ•ด์ฃผ์„ธ์š”.
๋ช‡ ๊ฐ€์ง€ ํ”ผ๋“œ๋ฐฑ์„ ๋‚จ๊ฒผ์œผ๋‹ˆ ์ˆ˜์ •ํ•˜์‹œ๋ฉด์„œ ๊ผญ ์ฐธ๊ณ  ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.


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

public class Main {
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์—์„œ๋Š” ๋กœ์ง์„ ์‹œ์ž‘ํ•˜๋Š” ์ •๋„์˜ ์ฑ…์ž„๋งŒ ๊ฐ€์ง€๋Š”๊ฒŒ ๋” ์ ์ ˆํ•ฉ๋‹ˆ๋‹ค.
๊ทธ ์ž์ฒด๋กœ๋„ ์ง„์ž…์  ์—ญํ• ์„ ํ•˜๊ณ  ์žˆ๊ฑฐ๋“ ์š”.

Copy link
Author

Choose a reason for hiding this comment

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

9a3199f

๋ฉ”์ธ ์ง„์ž…์ ์„ ๋ถ„๋ฆฌํ–ˆ์Šต๋‹ˆ๋‹ค!

@@ -1,5 +1,5 @@
package com.racing.utils;

public interface RandomMover {
public interface RandomStrategy {
Copy link
Member

Choose a reason for hiding this comment

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

์ด ์ธํ„ฐํŽ˜์ด์Šค๋ช…์—์„œ Random์„ ์–ธ๊ธ‰ํ•˜๋ฉด ๊ตฌ์ฒด์ ์ธ ๋ฐฉ๋ฒ•์„ ๋ช…์‹œํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.
์ธํ„ฐํŽ˜์ด์Šค๋Š” ๋ฐฉํ–ฅ์„ "์ œ์‹œ"ํ•˜๋Š” ์šฉ๋„๋กœ๋งŒ ์‚ฌ์šฉํ•˜์‹œ๋Š”๊ฒŒ ์ข‹์•„์š”.

๊ทผ๋ฐ ์ด ์ธํ„ฐํŽ˜์ด์Šค๋Š” ์ด๋ฏธ ๋ฐฉํ–ฅ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ๊ฐˆ ๊ธธ๊นŒ์ง€ ์ „๋ถ€ ์•Œ๋ ค์ฃผ๋Š” ๋Š๋‚Œ์ด๋„ค์š”.

Copy link
Author

Choose a reason for hiding this comment

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

81149cf

RandomStrategy -> MovementStrategy ๋กœ ๋ณ€๊ฒฝํ–ˆ์Šต๋‹ˆ๋‹ค!
์ธํ„ฐํŽ˜์ด์Šค๋ช…์—์„œ ๊ตฌ์ฒด์ ์ธ ๋‚ด์šฉ์„ ์ œ๊ฑฐํ•˜๋Š” ๋ฐฉํ–ฅ์œผ๋กœ ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค.

for (Car car : carList) {
car.move();
private static void moveAllCars(Cars cars) {
RacingHelper racingHelper = new RacingHelper();
Copy link
Member

Choose a reason for hiding this comment

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

RacingHelper ๋ณด๋‹ค๋Š” ๋” ๊ดœ์ฐฎ์€ ์ด๋ฆ„์œผ๋กœ ๋ณ€๊ฒฝํ•ด์ฃผ์„ธ์š”.
์ƒ์œ„ ์ธํ„ฐํŽ˜์ด์Šค์ธ RandomStrategy ๋ฅผ ์—ฐ์ƒํ•ด๋‚ด๊ธฐ ์–ด๋ ต์Šต๋‹ˆ๋‹ค.
์ธํ„ฐํŽ˜์ด์Šค์˜ ์ด๋ฆ„์ด ์ด๋ฏธ ํ•˜์œ„ ๊ตฌํ˜„์ฒด์˜ ์—ญํ• ์„ ์ •ํ•ด๋ฒ„๋ ค์„œ ๊ทธ๋Ÿฐ ๊ฒƒ์ผ์ˆ˜๋„ ์žˆ์–ด์š”.

๊ทธ๋ฆฌ๊ณ  ํ•˜์œ„ ๊ตฌํ˜„์ฒด๋ฅผ ๊ทธ๋Œ€๋กœ ์‚ฌ์šฉํ•˜๋ฉด ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ํ†ตํ•œ ์•ฝ๊ฒฐํ•ฉ์ด๋ผ๋Š” ์žฅ์ ์„ ๊ฐ€์ ธ๊ฐˆ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.
๊ตฌํ˜„์ฒด๊ฐ€ ์•„๋‹ˆ๋ผ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ํ™œ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์œผ๋กœ ๋ฐ”๊ฟ”๋ณด์„ธ์š”.

๋ฐฉ๋ฒ•์€ ์—ฌ๋Ÿฌ๊ฐ€์ง€๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

  1. Car ์˜ ์ƒ์„ฑ์ž์—์„œ RandomStrategy ๋ฅผ ์ฃผ์ž…๋ฐ›์•„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
  2. moveAllCars ์—์„œ ์ง์ ‘ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  ๋งค๊ฐœ๋ณ€์ˆ˜ ํ˜•ํƒœ๋กœ RandomStrategy์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
    • ์ด๋ ‡๊ฒŒ ๋˜๋ฉด moveAllCars์—์„œ ์ง์ ‘ ์ƒ์„ฑํ•˜์ง€ ์•Š๊ณ  ์™ธ๋ถ€๋กœ๋ถ€ํ„ฐ ์ฃผ์ž…๋ฐ›๋Š” ํ˜•ํƒœ๊ฐ€ ๋ฉ๋‹ˆ๋‹ค.
    • ๋”ฐ๋ผ์„œ ์‚ฌ์šฉ์ž์˜ ํ•„์š”์— ๋”ฐ๋ผ ๋‹ค๋ฅธ ๊ตฌํ˜„์ฒด๋กœ ๋ฐ”๊พธ์–ด ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Copy link
Author

@jonghyeonLeee jonghyeonLeee Oct 22, 2024

Choose a reason for hiding this comment

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

47bdbbc

RacingHelper๋Š” ๋ถˆ๋ช…ํ™•ํ•œ ๋ถ€๋ถ„์ด ์žˆ์–ด ์ฐจ์˜ ์›€์ง์ž„์„ ๋‚˜ํƒ€๋‚ด๋Š” CarMovement๋กœ ๋ณ€๊ฒฝํ–ˆ์Šต๋‹ˆ๋‹ค.

moveAllCars์˜ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ๋ฐ›์•„์˜ค๋Š”๊ฑด ์ดํ•ดํ•˜์˜€์ง€๋งŒ ๊ตฌํ˜„์„ ์–ด๋–ป๊ฒŒ ํ• ์ง€ ๋„์ €ํžˆ ์ƒ๊ฐ๋‚˜์ง€ ์•Š์•„ ์ˆ˜์ •ํ•˜์ง€ ๋ชปํ–ˆ์Šท๋นˆ๋‹ค.. ใ…œใ…œ
ํ˜น์‹œ ์‹œ๊ฐ„ ๋‚˜์‹ค ๋•Œ ํŽ˜์–ด์ฝ”๋”ฉ์ด๋‚˜ ๋‹ค๋ฅธ ๋„์›€์„ ๋ฐ›์„ ์ˆ˜ ์žˆ๋Š” ๋ถ€๋ถ„์ด ์žˆ์„์ง€ ๋ฌธ์˜๋“œ๋ฆฝ๋‹ˆ๋‹ค!

Copy link
Member

Choose a reason for hiding this comment

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

  1. service์˜ ํ•„๋“œ์— CarMovement ๋ฅผ ํ•„๋“œ๋กœ ๊ฐ€์ง‘๋‹ˆ๋‹ค. ๊ทธ๋Ÿผ service๋ฅผ ์ดˆ๊ธฐํ™”ํ•  ๋•Œ ์ „๋žต์„ ์„ ํƒ์ ์œผ๋กœ ๋ฐ€์–ด๋„ฃ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  2. moveAllCars์˜ ๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ ์ง€๊ธˆ cars ํ•˜๋‚˜๋งŒ ์žˆ๋Š”๋ฐ cars, movementStrategy 2๊ฐœ๋กœ ํ•ด๋‘์‹œ๋ฉด ์ด ๋ฉ”์†Œ๋“œ๋ฅผ ํ˜ธ์ถœํ•  ๋•Œ ์ „๋žต์„ ์„ ํƒ์ ์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ „๋žต ํŒจํ„ด์˜ ๊ธฐ๋ณธ์€ ์–ธ์ œ๋“ ์ง€ ์ „๋žต์„ ๋ฐ”๊พธ์–ด ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์–ด์•ผ ํ•œ๋‹ค๋Š” ๊ฒƒ์ž„์„ ์ƒ๊ฐํ•ด๋ณด์‹œ๋ฉด ๋„์›€์ด ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.


import java.util.Objects;

public class CarName {
Copy link
Member

Choose a reason for hiding this comment

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

์›์ž ๋‹จ์œ„์˜ ์ฑ…์ž„ ๋ถ„๋ฆฌ ๐Ÿ‘


import java.util.Objects;

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.

๐Ÿ‘

Comment on lines 58 to 62
public void printRacingPositions() {
for (Car car : carList) {
System.out.println(car.displayRacingPosition());
}
}
Copy link
Member

Choose a reason for hiding this comment

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

domain์—์„œ๋Š” sout ์„ ์‚ฌ์šฉํ•˜์‹œ๋ฉด UI๋ฅผ ๋ถ„๋ฆฌํ•œ ์˜๋ฏธ๊ฐ€ ํ‡ด์ƒ‰๋ฉ๋‹ˆ๋‹ค.

sout์€ UI์—์„œ๋งŒ ์‚ฌ์šฉํ•ด์ฃผ์„ธ์š”.

Copy link
Author

Choose a reason for hiding this comment

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

16ee9f8

ํ•ด๋‹น ๋‚ด์šฉ ์ ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค :)

import java.util.stream.Collectors;

public class Cars {
List<Car> carList;
Copy link
Member

Choose a reason for hiding this comment

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

private์ด ์•„๋‹Œ ์ด์œ ๊ฐ€ ์žˆ์„๊นŒ์š”?

๊ทธ๋ฆฌ๊ณ  List์™€ ๊ฐ™์€ ์ž๋ฃŒํ˜•์€ ํ•„์š”์— ๋”ฐ๋ผ ์–ธ์ œ๋“ ์ง€ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์˜ˆ๋ฅผ ๋“ค๋ฉด Set์œผ๋กœ ๋ฐ”๊ฟ€ ์ˆ˜ ์žˆ๊ฒ ์ฃ ?

๋”ฐ๋ผ์„œ carList๋ณด๋‹ค๋Š” ๋ณต์ˆ˜ํ˜• ์šฉ์–ด๋ฅผ ์‚ฌ์šฉํ•˜์‹œ๋Š”๊ฑธ ์ถ”์ฒœ๋“œ๋ฆฝ๋‹ˆ๋‹ค.
Cars์ฒ˜๋Ÿผ ์ผ๊ธ‰์ปฌ๋ ‰์…˜์ธ ๊ฒฝ์šฐ์—๋Š” items ๊ฐ™์€ ์šฉ์–ด๋ฅผ ์‚ฌ์šฉํ•ด๋„ ๋‚˜์˜์ง€ ์•Š์•„์š”.

Copy link
Author

Choose a reason for hiding this comment

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

be64fc4

private๋กœ ํ•„๋“œ๋ฅผ ๋ง‰์•˜์–ด์•ผ ํ–ˆ๋Š”๋ฐ ๋นผ๋จน์—ˆ๋„ค์š” ใ…œใ…œ ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค.
items๋กœ ๋ณ€๊ฒฝํ•  ๊ฒฝ์šฐ Cars.getItems() ์™€ ๊ฐ™์ด ์ผ๋ฐ˜์ ์ธ ๋ฉ”์„œ๋“œ๋กœ ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ์–ด ๊ฐ€๋…์„ฑ์—์„œ๋„ ์ข‹์•„ ๋ณด์—ฌ ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค.

์ค‘๋ณต๋œ ๊ฐ’์— ๋Œ€ํ•œ ์ฒ˜๋ฆฌ ์—ฌ๋ถ€๊ฐ€ ๋ฌธ์ œ์— ๋ช…์‹œ๋˜์ง€ ์•Š์•„ ์Šต๊ด€์ ์œผ๋กœ List๋ฅผ ์‚ฌ์šฉํ–ˆ๋Š”๋ฐ ์ถ”ํ›„ ๊ด€๋ จ๋œ ๋‚ด์šฉ์ด ์žˆ์œผ๋ฉด Set์œผ๋กœ ๋ฆฌํŒฉํ† ๋ง ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค! :)

Comment on lines 15 to 17
public Cars(List<Car> carList) {
this.carList = carList;
}
Copy link
Member

Choose a reason for hiding this comment

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

๋ฐฉ์–ด์  ๋ณต์‚ฌ ๊ธฐ๋ฒ•์— ๋Œ€ํ•ด ๊ณต๋ถ€ํ•ด๋ณด์‹œ๋ฉด ์ข‹์Šต๋‹ˆ๋‹ค.

Cars๋ฅผ ์ƒ์„ฑํ•œ ์œ„์น˜ ์ฃผ๋ณ€์—์„œ Cars๋ฅผ ์ƒ์„ฑํ•˜๋Š”๋ฐ ์‚ฌ์šฉํ•œ List๋ฅผ ๋ณ€๊ฒฝํ•˜๋ฉด Cars๋„ ์˜ํ–ฅ์„ ๋ฐ›๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

Copy link
Author

Choose a reason for hiding this comment

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

13b1a3c

๋ฐฉ์–ด์  ๋ณต์‚ฌ ๊ธฐ๋ฒ• ๊ณต๋ถ€ ํ›„ ์™ธ๋ถ€์—์„œ ๋ณ€๊ฒฝํ•˜์ง€ ๋ชปํ•˜๋„๋ก ํ•ด๋‹น ๋‚ด์šฉ ๋ฐ˜์˜ ํ–ˆ์Šต๋‹ˆ๋‹ค.

Comment on lines 23 to 25
public List<Car> getCarList() {
return this.carList;
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public List<Car> getCarList() {
return this.carList;
}
public List<Car> getCarList() {
return Collections.unmodifiableList(this.carList);
}

์ฝ๊ธฐ ์ „์šฉ ๋ฐ์ดํ„ฐ๋กœ ๋ณ€๊ฒฝํ•ด์„œ ๋‚ด๋ณด๋‚ด์…”์•ผ ์™ธ๋ถ€์˜ ์˜ํ–ฅ์„ ๋ฐ›์ง€ ์•Š๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.
getCarList().add(car) ๋ฅผ ์ˆ˜ํ–‰ํ•˜๋ฉด Cars๊ฐ€ ๋ณ€๊ฒฝ๋˜์–ด ๋ฒ„๋ฆฝ๋‹ˆ๋‹ค.

return this.carList;
}

public int findMaxPosition() {
Copy link
Member

Choose a reason for hiding this comment

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

private ๋ฉ”์†Œ๋“œ์—ฌ๋„ ๊ดœ์ฐฎ์ง€ ์•Š์„๊นŒ์š”?

Copy link
Author

@jonghyeonLeee jonghyeonLeee Oct 22, 2024

Choose a reason for hiding this comment

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

0c567b0

์ž‘์„ฑํ•  ๋•Œ ์ง์ ‘ ํ…Œ์ŠคํŠธ๋ฅผ ํ•˜์˜€๋Š”๋ฐ ์ถ”ํ›„ ๊ฐ„์ ‘ ํ…Œ์ŠคํŠธ๋ฅผ ํ•˜๊ณ  ์žˆ๋‹ค ํŒ๋‹จํ•˜์—ฌ private ๋ณ€๊ฒฝ ํ›„ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์ œ๊ฑฐํ–ˆ์Šต๋‹ˆ๋‹ค!
์ผ๋ฐ˜์ ์œผ๋กœ ์ด๋Ÿฐ์‹์œผ๋กœ ์ฒ˜๋ฆฌํ•˜๋Š”์ง€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค!

Copy link
Member

Choose a reason for hiding this comment

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

private ๋„ ํ…Œ์ŠคํŠธ๊ฐ€ ํ•„์š”ํ•  ๋งŒํผ ๋ณต์žกํ•œ ์ˆœ๊ฐ„๋„ ๋ถ„๋ช… ์žˆ์ง€๋งŒ, public์„ ํ†ตํ•ด ๊ฐ„์ ‘์ ์œผ๋กœ ํ…Œ์ŠคํŠธํ•˜๋Š”๊ฒŒ ๋ฐฉ๋ฒ• ์ž์ฒด๊ฐ€ ๋” ์˜ฌ๋ฐ”๋ฆ…๋‹ˆ๋‹ค.

private์„ ๊ตณ์ด ๋”ฐ์ง€์ž๋ฉด public์˜ ์ฝ”๋“œ๋ฅผ ๋”ฐ๋กœ ์ ‘์–ด๋‘” ๋Š๋‚Œ์ด๋‹ˆ๊นŒ์š”.

@jonghyeonLeee
Copy link
Author

์•ˆ๋…•ํ•˜์„ธ์š”!
ํ”ผ๋“œ๋ฐฑ ๋‚ด์šฉ ๋ฐ˜์˜ํ•˜์—ฌ ์ปค๋ฐ‹ํ–ˆ์Šต๋‹ˆ๋‹ค!
๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!

Copy link
Member

@dhmin5693 dhmin5693 left a comment

Choose a reason for hiding this comment

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

์•ˆ๋…•ํ•˜์„ธ์š”.

๋งˆ์ง€๋ง‰ ๋ฏธ์…˜์ด๋ผ ์ผ๋‹จ ์ˆ˜์ • ์š”์ฒญ ํ•œ๋ฒˆ ๋” ๋“œ๋ ค๋ณด๋Š”๋ฐ์š”,
์‹œ๊ฐ„ ์ƒ ๋‹ค์Œ ๋ฏธ์…˜ ์ˆ˜ํ–‰ํ•˜์‹œ๋Š”๊ฒŒ ๋” ๋„์›€์ด ๋  ๊ฒƒ ๊ฐ™๊ธฐ๋Š” ํ•ฉ๋‹ˆ๋‹ค.

์ผ๋‹จ ๋‚จ๊ธด ํ”ผ๋“œ๋ฐฑ ํ™•์ธํ•ด๋ณด์‹œ๊ณ  ์ˆ˜์ •์ด ํ•„์š”์—†๋‹ค๊ณ  ์ƒ๊ฐํ•˜์‹œ๊ฑฐ๋‚˜ ๋‹ค์Œ ๋ฏธ์…˜ ์ง„ํ–‰ํ•˜๊ณ  ์‹ถ์œผ์‹œ๋ฉด ์ˆ˜์ •์—†์ด ๋ฐ”๋กœ ์š”์ฒญ์ฃผ์…”๋„ ๊ดœ์ฐฎ์Šต๋‹ˆ๋‹ค.

์–ด๋ ค์šด ์  ์žˆ์œผ์‹ค ๋•Œ ๋˜ DM์ฃผ์‹œ๋ฉด ์ƒ์„ธํžˆ ๋‹ต๋ณ€๋“œ๋ฆฌ๊ฒ ์Šต๋‹ˆ๋‹ค.

import java.util.List;

public class RacingService {
public static void startRacingGame() {
Copy link
Member

Choose a reason for hiding this comment

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

startRacingGame์—์„œ input๊นŒ์ง€ ๋‹ค ํ•˜๊ธฐ๋ณด๋‹ค๋Š” input์€ ๋ฏธ๋ฆฌ ๋ฐ›์€ ๋’ค dto ๋“ฑ์œผ๋กœ ๋„˜๊ธฐ๋ฉด ์กฐ๊ธˆ ๋” ๊น”๋”ํ•˜๊ฒŒ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™๋„ค์š”.

Comment on lines 48 to 54
private static void advanceAllCars(Cars cars) {
RacingHelper racingHelper = new RacingHelper();

for (Car car : cars.getCarList()) {
car.move(racingHelper.shouldMove());
}
}
Copy link
Member

Choose a reason for hiding this comment

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

startRacingGame์—์„œ ์ง์ ‘ input์„ ์ˆ˜ํ–‰ํ•˜์ง€ ์•Š๊ณ  Main(ํ˜น์€ ๋‹ค๋ฅธ ํด๋ž˜์Šค)์—์„œ input์„ ์ˆ˜ํ–‰ํ•œ ๋‹ค์Œ dto๋กœ ๋ณด๋‚ธ๋‹ค๋ฉด ์–ด๋–จ๊นŒ์š”?

startRacingGame ์ž์ฒด ํ…Œ์ŠคํŠธ๊ฐ€ ์ง€๊ธˆ์€ ๋ถˆ๊ฐ€๋Šฅํ•œ๋ฐ ๊ฐ€๋Šฅํ•ด์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ํ•˜์ง€๋งŒ ์•„์ง ๊ฑธ๋ฆผ๋Œ์ด ํ•˜๋‚˜ ์žˆ๋Š”๋ฐ advanceAllCars ์—์„œ ์ง์ ‘์ ์œผ๋กœ Random ๋กœ์ง์— ์˜์กดํ•˜๊ณ  ์žˆ์–ด์š”.
DM์œผ๋กœ ๋ง์”€๋“œ๋ ธ๋“ฏ ์—ฌ๊ธฐ์„œ ์ด๋ ‡๊ฒŒ ์ง์ ‘ ์‚ฌ์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์— startRacingGame ๊ฐ€ ๋ถˆ๊ฐ€๋Šฅํ•ด ์ง€๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

RacingService ์˜ ํ•„๋“œ๋กœ Strategy๋ฅผ ๊ฐ€์ ธ๊ฐ€๊ณ  ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•๋„ ์žˆ์œผ๋‹ˆ ํ•œ ๋ฒˆ ๊ณ ๋ คํ•ด๋ณด์„ธ์š”.

return this.carList;
}

public int findMaxPosition() {
Copy link
Member

Choose a reason for hiding this comment

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

private ๋„ ํ…Œ์ŠคํŠธ๊ฐ€ ํ•„์š”ํ•  ๋งŒํผ ๋ณต์žกํ•œ ์ˆœ๊ฐ„๋„ ๋ถ„๋ช… ์žˆ์ง€๋งŒ, public์„ ํ†ตํ•ด ๊ฐ„์ ‘์ ์œผ๋กœ ํ…Œ์ŠคํŠธํ•˜๋Š”๊ฒŒ ๋ฐฉ๋ฒ• ์ž์ฒด๊ฐ€ ๋” ์˜ฌ๋ฐ”๋ฆ…๋‹ˆ๋‹ค.

private์„ ๊ตณ์ด ๋”ฐ์ง€์ž๋ฉด public์˜ ์ฝ”๋“œ๋ฅผ ๋”ฐ๋กœ ์ ‘์–ด๋‘” ๋Š๋‚Œ์ด๋‹ˆ๊นŒ์š”.

@@ -5,7 +5,7 @@
/**
* ๋ ˆ์ด์‹ฑ์—์„œ ์‚ฌ์šฉ ํ•  ํ—ฌํผ ๋ฉ”์„œ๋“œ๋ฅผ ๋ชจ์•„๋†“์€ ํด๋ž˜์Šค
*/
public class RacingHelper implements MovementStrategy {
public class CarMovement implements MovementStrategy {
Copy link
Member

Choose a reason for hiding this comment

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

MoveStrategy๋Š” ์ ์ ˆํ•œ ๋ช…์นญ์ด ๋งž๋Š”๋ฐ์š”,
CarMovement ๋ณด๋‹ค๋Š” RandomMovementStrategy๋Š” ์–ด๋– ์‹ ์ง€์š”?

์ €๋ฒˆ์—๋„ ๋‚จ๊ธด ๋ถ€๋ถ„์ธ๋ฐ ๊ตฌํ˜„์ฒด์™€ ์ธํ„ฐํŽ˜์ด์Šค๋Š” ์ด๋ฆ„์œผ๋กœ๋„ ์—ฐ๊ด€์ด ์žˆ์–ด๋ณด์—ฌ์•ผ ์ข‹์Šต๋‹ˆ๋‹ค.

for (Car car : carList) {
car.move();
private static void moveAllCars(Cars cars) {
RacingHelper racingHelper = new RacingHelper();
Copy link
Member

Choose a reason for hiding this comment

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

  1. service์˜ ํ•„๋“œ์— CarMovement ๋ฅผ ํ•„๋“œ๋กœ ๊ฐ€์ง‘๋‹ˆ๋‹ค. ๊ทธ๋Ÿผ service๋ฅผ ์ดˆ๊ธฐํ™”ํ•  ๋•Œ ์ „๋žต์„ ์„ ํƒ์ ์œผ๋กœ ๋ฐ€์–ด๋„ฃ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  2. moveAllCars์˜ ๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ ์ง€๊ธˆ cars ํ•˜๋‚˜๋งŒ ์žˆ๋Š”๋ฐ cars, movementStrategy 2๊ฐœ๋กœ ํ•ด๋‘์‹œ๋ฉด ์ด ๋ฉ”์†Œ๋“œ๋ฅผ ํ˜ธ์ถœํ•  ๋•Œ ์ „๋žต์„ ์„ ํƒ์ ์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ „๋žต ํŒจํ„ด์˜ ๊ธฐ๋ณธ์€ ์–ธ์ œ๋“ ์ง€ ์ „๋žต์„ ๋ฐ”๊พธ์–ด ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์–ด์•ผ ํ•œ๋‹ค๋Š” ๊ฒƒ์ž„์„ ์ƒ๊ฐํ•ด๋ณด์‹œ๋ฉด ๋„์›€์ด ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants