Fizz Buzz Kata

_config.yml

Folks, have you ever heard of the fizz buzz problem kata? It’s quite simple really. Here are the rules:

“Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.”

Looks simple enough. The first time I saw this problem, one thing screamed at me: Factory method and polymorphism. I could see the solution a mile away. Choose the object based on its divisibility in the factory method. Then supply its behaviour. And I forced the outcome using tests. I refactored a couple of times and broke a few rules along the way while doing it (probably should hey?) but this is the final result.

It’s elegant, readable, simple, and very, very OOP. You could probably go for a simpler approach, but that wouldn’t quite be OOP now, would it?

Here is the code:

And here are my tests:

Any questions, please feel free to ask.

Written on April 19, 2017