Thursday, March 21, 2013

private rovering

The code in Kent's book is all Java, but as I follow through I'm coding in Ruby, and this change led to some interesting discoveries.

After changing an attribute in my class to private, my code stopped working for no apparent reason. After some googling I've found this article. The access specifiers (public, protected, private) have slightly different meanings in Ruby and Java. For my code to work, I had to use protected, while in Java I'd had used private. Interesting.

I've also learned about the Value Object design pattern. This is a cool pattern to implement small things like a pair of coordinates (x,y) and such. And that reminded me of last year's Thoughtworks Boot Camp I attended. They presented the Mars Rover problem to us. The rover position should be represented by two coordinates and the orientation, for example: 0,0,N. In this case, The rover would be on the top bottom left corner of the map, facing north. The position would be represented perfectly by something like this:

I don't know if there's anything more to this pattern, but Martin Fowler's book which describes it is already in my to do list.

No comments:

Post a Comment