This kata fictionalizes the experience of working with someone else's code. You'll probably groan when you first see the code provided to you. The amount of code isn't overwhelming, its the prefect balance to evoke the feeling, "I can't wait to re-write this cruft." It's suggested that you use Test Driven Development with this kata. Once done, read the **spoiler** section below to see if you had a similar experience or not.
Original posting: http://iamnotmyself.com/2011/02/13/refactor-this-the-gilded-rose-kata/
Ruby : https://github.com/professor/GildedRose
C#: https://github.com/NotMyself/GildedRose
Java : https://github.com/wouterla/GildedRose
AS3: https://github.com/dshefman/GildedRoseAS3
The Gilded Rose Kata was developed by Terry Hughes and Bobby Johnson and presented to the SC community on 2/13/2011.
Hi and welcome to team Gilded Rose. As you know, we are a small inn with a prime location in a prominent city ran by a friendly innkeeper named Allison. We also buy and sell only the finest goods. Unfortunately, our goods are constantly degrading in quality as they approach their sell by date. We have a system in place that updates our inventory for us. It was developed by a no-nonsense type named Leeroy, who has moved on to new adventures. Your task is to add the new feature to our system so that we can begin selling a new category of items. First an introduction to our system:
Pretty simple, right? Well this is where it gets interesting:
We have recently signed a supplier of conjured items. This requires an update to our system:
Feel free to make any changes to the UpdateQuality method and add any new code as long as everything still works correctly. However, do not alter the Item class or Items property as those belong to the goblin in the corner who will insta-rage and one-shot you as he doesn’t believe in shared code ownership (you can make the UpdateQuality method and Items property static if you like, we’ll cover for you).
**Spoilers** Note: you probably want to read this section after doing the kata.
1. Most of the students thought this was a great kata for practicing TDD.
We had a great conversation about what is the best way to test this? A few started with a given initial state and looped through update quality man times. They found that their test cases were as complicated as the code they were testing. Often this code was hard to follow or read. Many tested the individual requirements to verify that when we go from state N to state N+1, a certain invariant still holds true.
2. What is the purpose of the Goblin rule?
(I need to find my notes on the class response to this one.) Most agreed that it was ok to subclass item provided that you didn't touch the code in the item class. Just to be sure, I asked Terry this question and here is his answer: "basically if the goblin sees anything different inside the Item class, everyone dies"
This kata was simple, yet it gave me a decent proving ground for practicing TDD and refactoring my tests. I did this kata twice. The first time, I created a maze of code using if/else blocks to handle all of the special cases one by one. While working through the kata, I saw significant opportunities to refactor and make the code more readable. Refactoring took my update_quality method down from 51 messy lines to 18 lines of extremely readable code. I tried to refactor further to clearly define the business rules in an array or hash but found that the resultant code was less readable. I also worked to refactor my tests which had a lot of repletion in the spirit of being DRY. Although I was able to streamline my test suite down to an extremely DRY single 7 line test, I have mixed feelings about how it turned out. It's great to have a concise test suite but the tests will not be helpful since the test covers the entire code base. I think going forward, I will consider being less DRY if it gives me more granular insight into where a bug resides.
Updated on Apr 23, 2013 by pfeffed35