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.
Directionknows current direction and is able to turn either left or rightPositionis now solely responsible for the movement (depending on givenDirection)Robothas aDirectionandPositionand is able to follow instructions.I thought about implementing a separate
Moveclass. Which would turn the direction and advance the position. That approach would tighten the coupling between classes and add complexity.Also a
Mapwould 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
Robotproperties 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.