Skip to content

Step 5 - Car racing(Refactoring)#1816

Open
AparnaPattathil wants to merge 24 commits intonext-step:aparnapattathilfrom
AparnaPattathil:AparnaPattathil-step-5
Open

Step 5 - Car racing(Refactoring)#1816
AparnaPattathil wants to merge 24 commits intonext-step:aparnapattathilfrom
AparnaPattathil:AparnaPattathil-step-5

Conversation

@AparnaPattathil
Copy link

Hi Brie,
Thank you for all the valuable comments and guiding me through the challenge.
I have tried to refactor according to your comments in the previous PR.
Looking forward to your inputs for this one as well.

Copy link

@byjo byjo left a comment

Choose a reason for hiding this comment

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

Hey Aparna,
It is really nice to see you again in PR and we're finally at the last step!

I’ve left some feedback on areas that could be improved before wrapping up the mission.
Hope it helps you make the final touches. Let me know if you have any questions! 😊

import carracing.RandomNumberGenerator.getRandom
import carracing.view.ResultView

typealias RaceHistory = List<List<Car>>
Copy link

Choose a reason for hiding this comment

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

Continued with #1813 (comment)

So if I understand correct, the RaceHistory will be List<List>, right?

Yes, That's right!

Just a thought: what would change if RaceHistory were its own class rather than a typealias?
Would it give you more flexibility in handling race data or expressing domain logic more clearly?

}
}

fun setAsWinner(maxPosition: Int) {
Copy link

Choose a reason for hiding this comment

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

Is there a reason why Car needs a setter for isWinner?
What might be the trade-offs of exposing internal state like this versus encapsulating that logic?

Comment on lines +25 to +26
cars.forEach { it.setAsWinner(maxPosition) }
return cars.filter { it.isWinner }
Copy link

Choose a reason for hiding this comment

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

This version with setAsWinner() makes sense in terms of marking the winner.
However do you think we might be adding more state management than necessary here?
What if the Car just told us whether it's at the winning position, rather than us updating it?

return cars.filter { it.isPositionAt(maxPosition) }

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.

3 participants