Step3 지뢰찾기(게임실행)#399
Conversation
malibinYun
left a comment
There was a problem hiding this comment.
리뷰가 늦어져서 죄송합니다 😥
3단계 미션 고생 많으셨어요!
고민해보면 좋을 점들에 코멘트 남겨두었어요.
이전 미션에 달아두신 코멘트에도 답변 달아둘게요 :)
피드백 반영 후 다시 리뷰 요청 부탁드려요!
| private fun executeGame(mineMapMeta: MineMapMeta, mineMap: MineMap) { | ||
| val positionStack = Stack<Position>().apply { addAll(mineMap.values.keys) } | ||
| while (positionStack.isNotEmpty()) { | ||
| val position = positionStack.pop() | ||
| if (mineMap.getCell(position).openState == OpenState.OPENED) continue | ||
| OutputView.printOpenPositionMsg(position) | ||
| if (mineMap.isEmptyCellClicked(position)) { | ||
| OutputView.printMineMap(mineMapMeta, mineMap) | ||
| continue | ||
| } | ||
| OutputView.printGameLoseMsg() | ||
| break | ||
| } |
There was a problem hiding this comment.
view와 게임을 진행하는 도메인 로직이 섞여있는 것으로 보여요 :)
view의 일과 도메인의 일을 적절히 나눠보는 것은 어떨까요?
도메인에서 view의 일이 필요하다면, 전달 받아야 할 것들에 대해 interface를 작성하고, console에 대한 하위 구현체를 도메인 객체로 넘겨 의존 관계를 떼어낼 수 있겠어요 :)
| private fun createCell(position: Position, minePositions: Set<Position>): Cell { | ||
| val aroundPositions = position.aroundPositions() | ||
| return if (minePositions.contains(position)) { | ||
| Mine | ||
| Mine() | ||
| } else { |
There was a problem hiding this comment.
지뢰 판의 칸들이 열릴지 여부를 모르는 상태에서 미리 count를 모두 계산하는 것은 낭비라는 생각이 들어요.
칸이 열렸을 때, 그 때 count를 계산하게 만들어보는 것은 어떨까요?
| data class Empty( | ||
| val mineCount: Int = 0, | ||
| override val openState: OpenState = OpenState.CLOSED, | ||
| ) : Cell { | ||
| override fun open(): Empty { | ||
| return copy(openState = OpenState.OPENED) |
There was a problem hiding this comment.
Cell 하위 구현체로, Open인 Cell과 Close인 셀로 구현해보는 건 어떨까요?
|
|
||
| fun isEmptyCellClicked(position: Position): Boolean { |
There was a problem hiding this comment.
메서드 명만 봐서는, 빈 칸이 클릭되었는지에 대한 여부를 반환하기만 할 것처럼 보여요.
그런데 실제로 내부 구현에서는 칸을 열기까지 하네요!
다른 개발자들이 보았을 때 이 메서드에 대한 내용을 착각하고 잘못 사용할 수 있을 것으로 보여요.
메서드가 수행하고 있는 것을 더욱 구체적으로 작성해보는 건 어떨까요?
| val rowRange = (y - 1)..(y + 1) | ||
| val colRange = (x - 1)..(x + 1) |
There was a problem hiding this comment.
#389 (comment) 여전히 유효한 피드백이에요!
enum으로 Direction 등의 객체를 만들어보는 건 어떨까요? 그리고 이 객체로 8방향을 표현해보면 좋겠어요 :)
enum class Direction(
val dx :Int,
val dy: Int,
) {
TOP(0, 1)
TOP_LEFT(-1, 1)
...
...
}| require(minePositions.size == mineMapMeta.mineCount) { "지뢰의 개수가 맞지 않습니다." } | ||
| return minePositions |
윤혁님, 안녕하세요. step3 리뷰 요청드립니다!
작업 내용
질문
객체 간 의존도가 높아질 수록 테스트가 어려워지는 상황을 어떻게 개선해볼 수 있을까요? ( 관련 질문 )