Complexity dimensions - FizzBuzz part III
I want to stand out a similarity at this point with how I implemented each one of the previous simple dimensions
: I added first a test that forced me to have a special case (if statement). Then a second test that started to unveil some duplication but not enough to be sure. And finally, a third test that made the duplication obvious so I could refactor to the generic implementation.
The similarity is that the Fizz dimension
and the Buzz dimension
are like the second test on a simple dimension
: I have two examples of the names to combine. They unveil some duplication but not enough to be sure. I need to introduce a third example to make the duplication obvious and refactor to the generic implementation.
Based on that, I carry on (7:41-11:00) implementing a feature that is not mentioned in the requirements: the Bang dimension
. The following tests guide it:
And finally, from then to the end (11:00 - 16:21), I implement the generic simple dimensions
combination helped by the tests:
This way I end with this implementation:
There is still duplication in there, but it is not so related to demonstrate the complexity dimensions
concept. Just for curiosity’s sake, It could have been removed this way:
You might argue that the Bang dimension
was not in the requirements and therefore it shouldn’t be there. I agree. It served the purpose of unveiling enough duplication to be sure what would be the generic implementation.
We can remove the 'Bang => 7
factor and its related test if we want. Or, even better would have been to conform to the Open-Closed principle by, for example, creating a class and passing the factors in the constructor.