GildedRose-Refactoring-Kata/Java/README.md
2019-11-01 19:58:31 +01:00

1.8 KiB

Why refactoring ?

  • Ability to easily add new kind of items(like conjured)
  • However, without altering the Item class or Items property

Requirements

  • All items have a SellIn value which denotes the number of days we have to sell the item
  • All items have a Quality value which denotes how valuable the item is
  • At the end of each day our system lowers both values for every item

unit tests

  • At the end of each day our system lowers both values for every item
  • Once the sell by date has passed, Quality degrades twice as fast
  • The Quality of an item is never negative
  • "Aged Brie" actually increases in Quality the older it gets
  • The Quality of an item is never more than 50
  • "Sulfuras", being a legendary item, never has to be sold or decreases in Quality
  • "Backstage passes", like aged brie, increases in Quality as its SellIn value approaches;
    • Quality increases by 2 when there are 10 days or less and by 3 when there are 5 days or less but
    • Quality drops to 0 after the concert
  • an item can never have its Quality increase above 50
    • however "Sulfuras" is a legendary item and as such its Quality is 80 and it never alters.

Technical Issues, with a balanced priority

  • item names are hardcoded
  • items are identified by the name in a hardcoded way
  • nested logic
  • long method
  • plain logic
  • complex operations
  • Item properties are public
  • multiple access by index

Refactoring actions

  • extract hardcoded variables
  • create polymorphism for items
  • move item names as item members
  • extract methods
  • extract boolean methods
  • encapsulate methods
  • isolate specific logics
  • move specific logic to backstage
  • move specific logic of sulfuras