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 right
  • Position is now solely responsible for the movement (depending on given Direction)
  • Robot has a Direction and Position 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.