24 April 2014
24 April 2014

Code kata 6: The classic bowling game scorer, open and closed

The kata

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


  1. Write the first failing test. It should use a factory method to obtain the object(s) under test.
  2. Make the test pass.
  3. Write the next failing test.
  4. 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

    1. 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.
    2. Now make the test pass.
    3. 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).

Related posts

Also in Blog

Introducing DevOps to the US Government – Part 2

In the first post in this series, I talked about the challenges for the US Government sector when attempting to introduce DevOps. The sector lags behind others such as Financial Services on every meas...

Also in Software development

What’s the difference between blue/green and red/black deployments?

When deploying new versions of a centralized application like a web service, there’s a strategy you can use to direct production traffic to the new version only after it has been successfully de...

Also about Code Katas

Code kata 7: Producer-consumer problem

First, apologies for nodding off and not posting for the last few weeks. I have the usual set of excuses, which you can guess easily enough without the need to read them here.

So, on to the kata: som...

Also about SOLID

Code kata 5: SOLID chess

The kata

Let’s get this clear: we’re not going to write a chess-playing AI in this kata. The idea is a bit more humble: to write a program that can work out valid moves for a set of chess pieces....