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).

Share this post.

Share on FacebookShare on Google+Share on LinkedInTweet about this on Twitter

Related posts

Also in Software development

Diversity in tech – how can we close the growing gender gap?

Diversity is one of the most prominent issues faced by digital businesses today. Research from industry body Tech Nation shows that women in IT are outnumbered by men 4:1 and make up just 19% of the U...

Also in Blog

Six reasons to version control your database

For most application developers, it’s unthinkable to work without version control. The benefits of tracking and retaining an incremental history of code changes are long understood in the world of s...

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....