-
Notifications
You must be signed in to change notification settings - Fork 49
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
[둘리] 1, 2단계 영화 티켓 예매 제출합니다. #7
Changes from 1 commit
81ab027
545de51
766d546
4c79b1a
4396e2c
282882b
4690eae
2bc5a77
15cf193
c75d5a7
e38faa0
2616c9a
7c5e91f
761850e
013a294
adf25b7
f50a2ce
48a66c5
47f12c8
443e903
e7db664
aa74fa9
c05ff0e
fc093c7
3f5cc8f
b512714
6d2199c
520d74b
3ddf00b
fe47ef3
5525f7b
7dce42c
70e7f6b
6b3843c
c881fba
4d17d10
10f416c
303b877
ed85463
452126c
77afa95
54b5c30
8609c35
2e67294
187af84
6fc6324
a5e2e98
37cf719
b8c06a2
e2c4c55
0fe291d
dc6ad79
e062f6f
9864e56
5cca9a1
a45c442
9f8e452
d04bd6c
5336de6
77cd778
1c36e77
186d6f6
b1bffce
b13a913
f8c3245
ae36175
f2bfce9
1dc76f1
ac7b7e6
39215c6
b89051c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
package woowacourse.movie.model | ||
|
||
data class Movie( | ||
val image: Int, | ||
val title: String, | ||
val playingTimes: PlayingTimes, | ||
val runningTime: Int, | ||
val description: String | ||
) : java.io.Serializable | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package woowacourse.movie.model | ||
|
||
import androidx.annotation.DrawableRes | ||
|
||
data class MovieDTO( | ||
@DrawableRes val image: Int, | ||
val title: String, | ||
val playingTimes: PlayingTimes, | ||
val runningTime: Int, | ||
val description: String | ||
) : java.io.Serializable | ||
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. 도메인과 뷰에서 관리할 모델을 분리하셨네요 👍 다만 DTO는 안드로이드에서 사용하지 않는 용어입니다. spring 진영에서 자주 사용하는 용어예요. 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. Model이라는 단어를 사용하여 수정했습니다! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package woowacourse.movie.util | ||
|
||
import androidx.annotation.DrawableRes | ||
import woowacourse.movie.model.Movie | ||
import woowacourse.movie.model.MovieDTO | ||
|
||
fun MovieDTO.toDomain(): Movie { | ||
return Movie(title, playingTimes, runningTime, description) | ||
} | ||
|
||
fun Movie.toPresentation(@DrawableRes res: Int): MovieDTO { | ||
return MovieDTO(res, title, playingTimes, runningTime, description) | ||
} |
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.
run 스코프 함수를 선택한 이유가 무엇인가요?
다른 스코프 함수들과 어떻게 다를까요?
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.
scope function를 살펴보면 두 가지 기준으로 차이점이 나뉩니다.
it
인가,this
인가 :it
- let, also |this
- run, with, apply사실 run을 선택한 이유는 뜻 그대로 실행한다는 의미로 사용했는데요..!
위 기준에서 서로 겹치는 run과 with에 대해 좀 더 살펴보았습니다.
run과 with의 가장 큰 차이점은 (지금 코드에서 사용한 run의 경우) run은 확장함수이나 with는 아니라는 점, 그리고 run은 nullable 변수에서 사용 가능하나 with에서는 그렇지 않다는 점입니다.
with는 "이미 생성된" 객체에 대해 코드 중복을 줄이고 싶을 때, run은 객체 생성 후 "객체 저장 없이" 원하는 값만 받아오고 싶을 때도 사용할 수 있습니다.
따라서, 현재 코드에서는 객체가 nullable이 아니며, return값이 필요 없고 한 객체에 대해 여러 함수를 사용하려고 하고 있기 때문에 의미적으로 with가 보기 좋아보입니다!
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.
좋은 공부가 되었기를 바라요 :)
조금 추가하면,
with는 사실 나머지 4개와는 다르게 확장함수가 아니랍니다.
그래서 run과의 비교군으로는 잘 맞지 않아요.
저도 공감해요.
다만, run의 반환 값은
Lambda의 결과
라는 것이에요.그렇기에 이 반환 값을 사용하지 않으므로, 적절하지 않다고 생각해요.
저는 이런 경우, 수신 객체를 가지고 또 무언가를 수행하니,
also
를 주로 활용해요.확장 함수의 결과가 변환되지도 않기에 활용해요.
확장 함수에 대한 비교로 말씀 드렸는데, 둘리 의견 처럼 with가 더 적절해 보이네요 :)
제 의견은 정답이 아니니, 이런 의견도 있다 정도로 생각해주시면 좋겠어요 😊
다만, 이러한 일들이 정말 스코프 함수가 필요했는 지 더 고민해보면 좋겠어요.
정말 외부에서 일일이 MovieDetailViewInitializer 객체의 메서드를 호출해주어야할까요?
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.
일일히 호출하기 보다 생성자에서 Movie 데이터를 받아서 한번에 처리할 수 있을 것 같습니다. :)
그리고 한 가지 더 질문드리고 싶은 부분이 있습니다!
with를 찾아볼 때 블로그에 반환값이 없다라는 말을 자주 봤는데요!
with의 정의를 보면 반환 타입이 block의 결과인데... 반환은 있는게 맞지만, 이 반환값을 어딘가에 저장해서 사용하지는 않는다는 의미인건가요?
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.
정확히 짚으셨네요!
저는 사실 한글로 된 블로그에 그리 신뢰도가 높지 않아요.
생각보다 다른 블로그의 글을 그대로 옮겨다가 적는 경우가 꽤 많아요.
그렇기에 잘못된 정보도 그대로 옮기는 경우를 많이 보았어요.
저는 둘리가 건강한 검색을 하고 있다고 생각해요.
믿을 건 영어 공식 문서와 실제 코드입니다 🙂