mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 06:21:29 +00:00
2.2 KiB
2.2 KiB
This file documents my refactoring and design journey while working through in this kata.
NOTES:
- At this stage, I assume that when we're not supposed to change Item or Items, we shouldn't just ignore them and create a parallel object types to use (that include the different DailyUpdate behaviours).
- This code and requirements were simple enough that I could have created the final version, or at least a massive refactoring immediately. However, I wanted to experience and demonstrate the refactoring process by small steps that can be just as easily applied to more complex code.
My refactoring steps:
- Added full test coverage drawing from the requirements and the existing 30 days texttest test.
Some of the tests failed due to bugs I discovered in the code/existing tests (e.g. relying on exact name instead of the mentioned "code word"). I decorated these tests with[Ignore]until I get to a stage in the refactoring where I can easily fix the issues and re-introduce the tests. - small refactorings of the UpdateQuality() method to make it more readable and separate the different (unrelated) handling of the different types.
- Extract Increasing/Decreasing Quality into a method.
- Separated the processing of the different types from each other.
- Used the
Templatedesign pattern to create DailyUpdater abstract class and derived classes to handle the DailyUpdate's steps for the different types of items.
The different derived classes will be moved to their own files in the next PR. Left them together for now to show the steps. - Created a
Simple Factorymethod to return the appropriate DailyUpdater object for the item type. - Moved DailyUpdaterFactory to its own class.
- Moved the logic of "Once the sell by date has passed, Quality degrades twice as fast" into the DailyUpdater Template class since it's relevant to all types of items.
- Moved Decrease/IncreaseItem byValue to be 1 by default.
This is the state of the code now
Considered but dropped
This is all the design ideas/patterns I've considered but decided against
- It feels like Quality should have been a
TinyTypethat manages its own limits. However, since we're not allowed to change Item I'm not implementing this.