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

๐Ÿš€ 2๋‹จ๊ณ„ - ์ง€ํ•˜์ฒ  ๋…ธ์„  ๊ด€๋ฆฌ (์ง€ํ•˜์ฒ  ๋…ธ์„  ์ƒ์„ฑ) #956

Open
wants to merge 6 commits into
base: jeongwon-iee
Choose a base branch
from

Conversation

jeongwon-iee
Copy link

์•ˆ๋…•ํ•˜์„ธ์š”. PR ์š”์ฒญ์ด ๋งŽ์ด ๋Šฆ์–ด์กŒ์Šต๋‹ˆ๋‹ค.

์•„์ง ๋ฏธ์…˜์„ ๋‹ค ์™„๋ฃŒํ•˜์ง„ ์•Š์•˜๋Š”๋ฐ, ์ฝ”๋“œ ๋ณ€๊ฒฝ์ด ๋งŽ์•„์ ธ์„œ ๋ฆฌ๋ทฐ์š”์ฒญ ๋จผ์ € ๋“œ๋ ค๋ณด๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค...!

ํŠน๋ณ„ํžˆ ๋ฆฌ๋ทฐ ๋ฐ›๊ณ  ์‹ถ์€ ๋‚ด์šฉ์€ ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์ž‘์„ฑ

  • StationFixtures๋ฅผ ๋งŒ๋“ค์–ด subwayStation ์ƒ์„ฑํ•œ ๋ฐฉ๋ฒ•์ด ์ ์ ˆํ•œ์ง€
  • ํ…Œ์ŠคํŠธ ๋ฉ”์„œ๋“œ ๋ ˆ๋ฒจ์— @DirtiesContext ์‚ฌ์šฉํ•œ ๊ฒƒ์ด ์ ์ ˆํ•œ์ง€

๊ธฐ๋Šฅ ๊ตฌํ˜„

  • ์ฝ”๋“œ์ž‘์„ฑ ์ˆœ์„œ๊ฐ€ ์•„๋ž˜์™€ ๊ฐ™์•˜๋Š”๋ฐ ์ ์ ˆํ• ๊นŒ์š”?
    • ์ธ์ˆ˜ํ…Œ์ŠคํŠธ ์ž‘์„ฑ โ†’ ๋„๋ฉ”์ธ ์ž‘์„ฑ โ†’ ์ปจํŠธ๋กค๋Ÿฌ ์ž‘์„ฑํ•˜๋ ค๋‹ˆ ํ•„์š”ํ•ด dto ์ž‘์„ฑ โ†’ ์ปจํŠธ๋กค๋Ÿฌ ์ž‘์„ฑ โ†’ ์„œ๋น„์Šค ์ž‘์„ฑํ•˜๋ ค๋‹ˆ ์ธํ„ฐํŽ˜์ด์Šค๊ฐ€ ์žˆ์œผ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„ ์ธํ„ฐํŽ˜์ด์Šค ์ž‘์„ฑ โ†’ ์„œ๋น„์Šค ์ž‘์„ฑ
  • ๋„๋ฉ”์ธ์—์„œ ํ•„๋“œ๋ฅผ private์œผ๋กœ ์„ ์–ธํ–ˆ๋Š”๋ฐ, ์ด ๋•Œ setter๋Š” ์–ด๋Š ๋ฒ”์œ„๊นŒ์ง€ ๋งŒ๋“ค์–ด์•ผํ• ๊นŒ์š”? ์ผ๋‹จ getter๋งŒ ์—ด์–ด๋†“๊ณ  ํ•„์š”ํ•  ๋•Œ๋งˆ๋‹ค setter๋ฅผ ๋งŒ๋“œ๋Š” ๊ฒƒ์ด ์ ์ ˆํ• ๊นŒ์š”?
  • dto์—์„œ ํ•„๋“œ๋ฅผ private final๋กœ ๋‹ซ์•„๋†“์€ ๊ฒƒ

๊ตฌ์กฐ

  • request/response/domain ์œผ๋กœ ํŒจํ‚ค์ง€๋ฅผ ๋ถ„๋ฆฌํ•œ ๊ฒƒ.
  • ์ง€ํ•˜์ฒ  ์—ญ์ด๋“  ๋…ธ์„ ์ด๋“  ๊ตฌ๊ฐ„์ด๋“  C,R,U,D ๋กœ์ง์ด ์žˆ์œผ๋‹ˆ ์ธํ„ฐํŽ˜์ด์Šค ๋งŒ๋“ค๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„ ์ธํ„ฐํŽ˜์ด์Šค ์ถ”๊ฐ€ํ•œ ๊ฒƒ
  • ๊ทธ๋ฆฌ๊ณ  ๋งˆ์ง€๋ง‰์œผ๋กœ ์ „์ฒด์ ์œผ๋กœ ์ฝ”๋“œ๋ฅผ ๋ฆฌํŒฉํ„ฐ๋งํ•œ ๊ฒƒ์ด ๋ฏธ์…˜์˜ ๋ชฉํ‘œ์™€ ๊ฐ™์€ ๋ฐฉํ–ฅ์„ฑ์œผ๋กœ ๊ฐ€๊ณ  ์žˆ๋Š”์ง€ ์—ผ๋ ค๋ฉ๋‹ˆ๋‹ค.

๊ธฐ๋Šฅ ๊ตฌํ˜„์€ ์ข€ ๋” ์†๋„๋ฅผ ๋‚ด๋ณผ๊ฒŒ์š” ..!
๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค :)

Copy link
Contributor

@boorownie boorownie left a comment

Choose a reason for hiding this comment

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

์ฝ”๋“œ ์ž‘์—… ๋‹จ์œ„๊ฐ€ ํฌ๋ฉด ๋ง‰๋ง‰ํ•  ์ˆ˜ ์žˆ๋Š”๋ฐ ์ค‘๊ฐ„์— ๋ฆฌ๋ทฐ์š”์ฒญ ์ž˜ ํ•ด์ฃผ์…จ์–ด์š” ๐Ÿ‘
์งˆ๋ฌธ ์ฃผ์‹  ๋ถ€๋ถ„ ์œ„์ฃผ๋กœ ์ฝ”๋ฉ˜ํŠธ ๋‚จ๊ฒผ๊ณ  ์ถ”๊ฐ€๋กœ ๋ช‡๊ฐ€์ง€ ๋” ๋‚จ๊ฒผ์œผ๋‹ˆ ์ด์–ด์„œ ์ง„ํ–‰ํ•ด์ฃผ์„ธ์š”!

์งˆ๋ฌธ

์ฝ”๋“œ์ž‘์„ฑ ์ˆœ์„œ๊ฐ€ ์•„๋ž˜์™€ ๊ฐ™์•˜๋Š”๋ฐ ์ ์ ˆํ• ๊นŒ์š”?

  • ๋„ค ์ธ์ˆ˜ ํ…Œ์ŠคํŠธ๋ฅผ ํ†ตํ•ด ์š”๊ตฌ์‚ฌํ•ญ ์ดํ•ด๋ฅผ ํ•œ ํ›„ ๊ธฐ๋Šฅ ๊ตฌํ˜„์€ ํ•„์š”ํ•œ ์ˆœ์„œ์— ๋”ฐ๋ผ ์ง„ํ–‰ ๋˜๋Š” ๊ฒƒ ์ข‹์Šต๋‹ˆ๋‹ค!
  • ์ˆœ์„œ๊ฐ€ ์ •ํ•ด์ง„ ๊ฑด ์—†๊ณ  TDD๋ฅผ ํ•ด ๊ฐ€๋Š”๋ฐ ์žˆ์–ด์„œ ํŽธํ•œ ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.
  • ๊ฐœ์ธ์ ์œผ๋กœ๋Š” ์ธ์ˆ˜ ํ…Œ์ŠคํŠธ -> ์ปจํŠธ๋กค๋Ÿฌ -> ์„œ๋น„์Šค ํ…Œ์ŠคํŠธ -> ์„œ๋น„์Šค ์ˆœ์œผ๋กœ ๊ฐ€๊ฑฐ๋‚˜ ์ธ์ˆ˜ ํ…Œ์ŠคํŠธ -> ์ปจํŠธ๋กค๋Ÿฌ -> ๋„๋ฉ”์ธ ํ…Œ์ŠคํŠธ -> ๋„๋ฉ”์ธ ์ˆœ์œผ๋กœ ๊ฐ€๋Š”๊ฑธ ์„ ํ˜ธํ•ฉ๋‹ˆ๋‹ค.
  • DTO๋Š” ๊ตณ์ด ํ…Œ์ŠคํŠธ๋ฅผ ๋งŒ๋“ค์ง€ ์•Š๊ณ  ํ•„์š”ํ•  ๋•Œ ๋ฐ”๋กœ ๋ฐ”๋กœ ๋งŒ๋“ค์–ด์ค๋‹ˆ๋‹ค.

setter ์ž‘์„ฑ ๋ฒ”์œ„

  • ์ด๋Ÿฌํ•œ ์ด์œ ๋กœ ์ธํ•ด ์ €๋Š” ๊ฐ€๊ธ‰์ ์ด๋ฉด setter๋ฅผ ์„ ํ˜ธํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
  • ํ•„์š”ํ•  ๋•Œ getter๋ฅผ ๋งŒ๋“ค๊ณ  ๊ฐ์ฒด์˜ ์ƒํƒœ๋ฅผ ๋ณ€๊ฒฝํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค๋ฉด setter ๋ฉ”์„œ๋“œ๋ฅผ ๋งŒ๋“ค๊ธฐ ๋ณด๋‹ค๋Š” setter์™€ ๋‹ค๋ฅธ ์ด๋ฆ„(์ƒํƒœ๋ฅผ ๋ณ€๊ฒฝํ•˜๋Š” ์˜๋„๋‚˜ ๋ชฉ์ ์ด ๋“œ๋Ÿฌ๋‚˜๋Š”)์˜ ๋ฉ”์„œ๋“œ๋ฅผ ๋งŒ๋“ค์–ด ์ค„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!

* Then ์ง€ํ•˜์ฒ  ๋…ธ์„ ์ด ์ƒ์„ฑ๋œ๋‹ค
* Then ์ง€ํ•˜์ฒ  ๋…ธ์„  ๋ชฉ๋ก ์กฐํšŒ ์‹œ ์ƒ์„ฑํ•œ ๋…ธ์„ ์„ ์ฐพ์„ ์ˆ˜ ์žˆ๋‹ค
*/
@DirtiesContext
Copy link
Contributor

Choose a reason for hiding this comment

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

๊ฐ•์˜์—์„œ ๋‹ค๋ฃจ์—ˆ๋Š”๋ฐ ํ…Œ์ŠคํŠธ ํ™˜๊ฒฝ์„ ์ดˆ๊ธฐํ™” ํ•ด์ฃผ๋Š” ๋ฐฉ๋ฒ•์€ ์—ฌ๋Ÿฌ ๋ฐฉ๋ฒ•์ด ์žˆ์Šต๋‹ˆ๋‹ค.
DirtiesContext๋ฅผ ์‚ฌ์šฉํ•ด๋„ ์ดˆ๊ธฐํ™”ํ•ด์ฃผ๋Š”๋ฐ ํฐ ๋ฌธ์ œ๋Š” ์—†์ง€๋งŒ
์ธ์ˆ˜ ํ…Œ์ŠคํŠธ๊ฐ€ ๋งŽ์•„์ง€๋ฉด ์†๋„๊ฐ€ ๋Š๋ ค์งˆ ์ˆ˜ ์žˆ์–ด์„œ ๊ฐ€๊ธ‰์  ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ 
๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ๊ฑธ ๊ถŒ์žฅํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

์•„๋ž˜์˜ ๋ฐฉ๋ฒ• ๋“ฑ "์ธ์ˆ˜ ํ…Œ์ŠคํŠธ ์ดˆ๊ธฐํ™”" ํ‚ค์›Œ๋“œ๋กœ ์ฐพ์•„๋ณด์‹œ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”!
https://newwisdom.tistory.com/95

produces = MediaType.APPLICATION_JSON_VALUE
)
public ResponseEntity<LineResponse> createLine(@RequestBody LineRequest lineRequest) {
LineResponse line = this.lineService.create(lineRequest);
Copy link
Contributor

Choose a reason for hiding this comment

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

this๋ฅผ ๋ถ™์ด๋Š” ๊ฑด ์˜๋ฏธ์ƒ ํฐ ์ฐจ์ด๋Š” ์—†์ง€๋งŒ
์ €๋Š” ๊ฐœ์ธ์ ์œผ๋กœ ๊ฐ€๋…์„ฑ์„ ์œ„ํ•ด ์ƒ์„ฑ์ž๊ฐ€ ์•„๋‹ˆ๋ฉด ์ œ๊ฑฐํ•˜๋Š” ํŽธ ์ž…๋‹ˆ๋‹ค.

Copy link
Author

Choose a reason for hiding this comment

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

์ €๋Š” private ๋ฉค๋ฒ„์—๋Š” this๋ฅผ ๋ถ™์ด๋Š” ํŒจํ„ด์„ ๊ฐ€์ง€๊ณ  ์žˆ์—ˆ๋Š”๋ฐ ๋ง์”€ ์ฃผ์‹  ๋•์— ๋‹ค์‹œ ํ•œ ๋ฒˆ ์ƒ๊ฐํ•ด๋ณด๊ฒŒ ๋˜๋„ค์š”! ์ด ๊ธฐํšŒ์— this๋ฅผ ์™œ ์“ฐ๋Š”์ง€ ์งš๊ณ  ๋„˜์–ด๊ฐ€์•ผํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค...

@@ -0,0 +1,12 @@
package subway;

public interface SubwayService<T, V> {
Copy link
Contributor

Choose a reason for hiding this comment

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

์„œ๋น„์Šค ๋ ˆ์ด์–ด์˜ ์ธํ„ฐํŽ˜์ด์Šค ๋ถ„๋ฆฌ ์‹œ๋„ ๐Ÿ‘
ํ•˜์ง€๋งŒ ํฐ ๋ชฉ์  ์—†์ด ๋ฐ˜๋ณต์ ์œผ๋กœ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๋ถ„๋ฆฌํ•˜์‹ ๊ฑฐ๋ผ๋ฉด ๋ฐ”๋กœ ๊ตฌํ˜„์ฒด๋ฅผ ๋งŒ๋“ค์–ด๋„ ์ข‹๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.

์•„๋ž˜ ๋งํฌ ์ฐธ๊ณ ํ•ด์ฃผ์„ธ์š”!
https://velog.io/@hsw0194/Spring-Boot%EC%97%90%EC%84%9C-interface%EB%A5%BC-%EC%82%AC%EC%9A%A9%ED%95%B4%EC%95%BC-%ED%95%A0%EA%B9%8C

Copy link
Author

Choose a reason for hiding this comment

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

StaionService, LineService, StationService ๋ชจ๋‘ ๋™์ผํ•˜๊ฒŒ ์ƒ์„ฑ, ์กฐํšŒ, ๋ชฉ๋ก, ์‚ญ์ œ ๋ฉ”์„œ๋“œ๊ฐ€ ์žˆ๊ธฐ์—
SubwayService๋กœ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๋งŒ๋“ค์–ด๋†“๊ณ  ์žฌ์‚ฌ์šฉํ•˜๋Š”๊ฒŒ ์œ ์ง€๋ณด์ˆ˜ ์ธก๋ฉด์—์„œ ์ข‹์„ ๊ฒƒ ๊ฐ™๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ์Šต๋‹ˆ๋‹ค โ˜ป

src/main/java/subway/line/domain/Line.java Show resolved Hide resolved
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