2 minutes
Robot Simulator Chapter 2
This article is part of my #100DaysOfCode and #100DaysOfBlogging challenge. R1D24
After a mentor left some feedback:
I like that you’ve split out the direction and position. I think you can go a bit further though.
I went back to the drawing board. 😊 Seriously, I read the feedback on my mobile and let the thought process do its work. Then I took pen and paper and outlined an improved structure. The result can be found on GitHub. Where I might upload all my solutions.
Thanks for the feedback.
I gave it some more thought and came up with the now submitted solution.
Direction
knows current direction and is able to turn either left or rightPosition
is now solely responsible for the movement (depending on givenDirection
)Robot
has aDirection
andPosition
and is able to follow instructions.I thought about implementing a separate
Move
class. Which would turn the direction and advance the position. That approach would tighten the coupling between classes and add complexity.Also a
Map
would IMO only make sense to place n Robots on it.I’m pretty happy with the outcome. One improvement I would add is either making
Robot
properties private and adding getters and setters or declare type properties. Now it would be possible to mutate them to whatever.Looking forward to hearing from you.