Skip to content

Step 5 - Car racing(Refactoring) #1816

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

Open
wants to merge 24 commits into
base: aparnapattathil
Choose a base branch
from

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! 😊

@@ -1,7 +1,8 @@
package carracing

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?

@@ -12,6 +16,10 @@ class Car(val name: String, var position: Int = INITIAL_POSITION) {
}
}

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