Code kata 6: The classic bowling game scorer, open and closed
Following on from last time, this is based on Uncle Bob’s now-famous bowling game kata, with the added spice of adhering to the open-closed principle of SOLID.
The kata is well-documented online, but briefly, the idea is to write a program that takes in a series of scores for each ball a person bowls in a bowling game and returns the resulting game score. And to guide us towards code the open to extension and closed to modification, we’re going to follow the workflow described at http://matteo.vaccari.name/blog/archives/293. This is how it works
- Write the first failing test. It should use a factory method to obtain the object(s) under test.
- Make the test pass.
- Write the next failing test.
- Try to make this test pass by only changing the factory and/or adding new classes.
If you find yourself modifying or adding functionality in existing non-factory classes
- Refactor the code so that you could proceed without changing these classes. The refactoring itself should provide no functional changes and the current test should still fail after the refactoring.
- Now make the test pass.
- Go to step 2.
Version control your code and commit frequently, so that we can see the process you went through at the discussion group.
You are free to implement the bowling game scorer in whatever order you want to, so long as you follow the workflow above. However, you might want to follow the suggestion below. If you need a hand with the bowling terminology and scoring rules, take a look at http://bowling.about.com/od/rulesofthegame/a/bowlingscoring.htm.
- A gutter ball game, where every bowl provides a score of 0.
- A one pointer game, where every bowl provides a score of 1.
- A game where many pins are knocked over in each bowl.
- A game where the first two bowls result in a spare.
- A game where the first bowl is a strike.
- A perfect game of all strikes – don’t forget that throwing a spare or strike in your last frame gives you up to an additional 1 or 2 shots (respectively).
Was this article helpful?