Object BootCamp - day11
Fred started talking about the final form of relation between objects - Collaboration. Collaboration is when two objects know each other and they interact and churn objects. Recursion is a form of churning objects. Basically, there are three parts to Recursion.
1. Original Question
2. Recursive Question and
3. Terminal Question
We did an exercise on Recursion. We chose to design and represent Graphs in objects. So we came up with a design for the same. We had a Node class whose job was to understand its neighbours. We then implemented canTraverseTo method that returns a boolean if we can traverse between two nodes. We used recursion to implement the same.
We then designed and implemented hopCountsTo method that returns the number of hops it takes to reach another node. I wrote the tests for the same and tried re-using the canTraverseTo method. The canTraverseTo method had an arraylist which held the visited nodes. So I refactored the class and ran the tests. I hit the green bar. I was happy and wrote more tests. Green bar again. Though I was a bit sceptical, my partner was very happy. We announced we had completed. When the entire class saw our code, they knew it wouldn't work. So we kept adding more tests and showing the green bar to them. Then we wrote a test that should fail. We hit the green bar again. Only then did we notice that we were running the wrong tests. That was embarassing.
0 Comments:
Post a Comment
<< Home