Back to the Game Looking back at the CRC
cards, I see that Game delegates add() to Frame. Why do we have to go through Game to add pinfalls? Since there's a composition relationship between Game and Frame (a Game has exactly 10 Frames), my initial thought was to make Frame an inner class of Game. So, as far as the outside world was concerned, the points were still being added to Game. IOW, the Frame was really just a part of the implementation.
However, I hadn't dug deep enough into JUnit to know how to set up test cases for inner classes. Also, in their article, the Bobs declared all their classes and test cases public so I decided to follow their lead for now. At this point, I didn't see that it would make a difference if I made Frame a public or inner class.
As I said, Game delegates add() to Frame. First, I add a private member array of 10 Frames. Then, I modify Game.add() to delegate to Frame. Refer to
Game.java (version 0.0.0004). I also add a private reference to the current Frame. Back to JUnit, load and run TestGame. Red bar: 100% fail. This is expected because getScore() is now wrong.
Oops, on more careful inspection of JUnit results, I see I have 3 Errors, not Failures. I realize that the _frames array has not been initialized. Cool. JUnit also helps me debug. I add a loop to initialize the array of Frames and save/compile. I won't increment the version# until I get a green bar.
I run JUnit again. Still red bar but this time I get 3 Failures instead of Errors.
Now to make getScore() working again. We now have Game collaborating with Frame to keep track of throws. I suppose Game will go to each Frame in turn and ask the number of pinfalls. So I write some code. Save/compile, then run TestGame in JUnit. Red bar, 2 failures. Only testTwoThrowsNoMark() is working again.
[This message has been edited by JUNILU LACAR (edited March 28, 2001).]