diff --git a/csharpcore/GildedRose/DailyUpdater.cs b/csharpcore/GildedRose/DailyUpdater.cs index ea49dccc..daea24c8 100644 --- a/csharpcore/GildedRose/DailyUpdater.cs +++ b/csharpcore/GildedRose/DailyUpdater.cs @@ -28,58 +28,4 @@ public abstract class DailyUpdater { item.Quality = int.Max(item.Quality - byValue, ItemQuality.MinQuality); } -} - -public class DailyUpdaterForRegularItems : DailyUpdater -{ - public override void UpdateQuality(Item item) - { - DecreaseQuality(item); - } -} - -public class DailyUpdaterForBetterWithAgeItems : DailyUpdater -{ - public override void UpdateQuality(Item item) - { - IncreaseQuality(item); - } -} - - -public class DailyUpdaterForBackstagePassesItems : DailyUpdater -{ - public override void UpdateQuality(Item item) - { - if (item.SellIn > 9) - { - IncreaseQuality(item); - } - else if (item.SellIn > 4) - { - IncreaseQuality(item, 2); - } - else if (!IsExpired(item)) - { - IncreaseQuality(item, 3); - } - else //Expired - { - DecreaseQuality(item, item.Quality); - } - } -} - -public class DailyUpdaterForLegendaryItems : DailyUpdater -{ - public override void UpdateSellIn(Item item) - { - // Legendary Items don't change over time - } - public override void UpdateQuality(Item item) - { - // Legendary Items don't change over time - } -} - - +} \ No newline at end of file diff --git a/csharpcore/GildedRose/DailyUpdaterForBackstagePassesItems.cs b/csharpcore/GildedRose/DailyUpdaterForBackstagePassesItems.cs new file mode 100644 index 00000000..a556dae9 --- /dev/null +++ b/csharpcore/GildedRose/DailyUpdaterForBackstagePassesItems.cs @@ -0,0 +1,24 @@ +namespace GildedRoseKata; + +public class DailyUpdaterForBackstagePassesItems : DailyUpdater +{ + public override void UpdateQuality(Item item) + { + if (item.SellIn > 9) + { + IncreaseQuality(item); + } + else if (item.SellIn > 4) + { + IncreaseQuality(item, 2); + } + else if (!IsExpired(item)) + { + IncreaseQuality(item, 3); + } + else //Expired + { + DecreaseQuality(item, item.Quality); + } + } +} \ No newline at end of file diff --git a/csharpcore/GildedRose/DailyUpdaterForBetterWithAgeItems.cs b/csharpcore/GildedRose/DailyUpdaterForBetterWithAgeItems.cs new file mode 100644 index 00000000..94c53397 --- /dev/null +++ b/csharpcore/GildedRose/DailyUpdaterForBetterWithAgeItems.cs @@ -0,0 +1,9 @@ +namespace GildedRoseKata; + +public class DailyUpdaterForBetterWithAgeItems : DailyUpdater +{ + public override void UpdateQuality(Item item) + { + IncreaseQuality(item); + } +} \ No newline at end of file diff --git a/csharpcore/GildedRose/DailyUpdaterForLegendaryItems.cs b/csharpcore/GildedRose/DailyUpdaterForLegendaryItems.cs new file mode 100644 index 00000000..09128942 --- /dev/null +++ b/csharpcore/GildedRose/DailyUpdaterForLegendaryItems.cs @@ -0,0 +1,13 @@ +namespace GildedRoseKata; + +public class DailyUpdaterForLegendaryItems : DailyUpdater +{ + public override void UpdateSellIn(Item item) + { + // Legendary Items don't change over time + } + public override void UpdateQuality(Item item) + { + // Legendary Items don't change over time + } +} \ No newline at end of file diff --git a/csharpcore/GildedRose/DailyUpdaterForRegularItems.cs b/csharpcore/GildedRose/DailyUpdaterForRegularItems.cs new file mode 100644 index 00000000..dbb7a1ff --- /dev/null +++ b/csharpcore/GildedRose/DailyUpdaterForRegularItems.cs @@ -0,0 +1,9 @@ +namespace GildedRoseKata; + +public class DailyUpdaterForRegularItems : DailyUpdater +{ + public override void UpdateQuality(Item item) + { + DecreaseQuality(item); + } +} \ No newline at end of file diff --git a/csharpcore/GildedRose/RefactoringDiary.md b/csharpcore/GildedRose/RefactoringDiary.md index 94778471..12efe822 100644 --- a/csharpcore/GildedRose/RefactoringDiary.md +++ b/csharpcore/GildedRose/RefactoringDiary.md @@ -22,6 +22,9 @@ The different derived classes will be moved to their own files in the next PR. L 10. Refactored DailyUpdaterFactory to reuse existing Updaters instead of creating new ones every time.
This could have been done using a dependency injection framework as well (to automatically create and reuse all the updaters). This might actually be the better way to do this. However, I've chosen to use the factory itself to manually manage it using a semi-flyweight pattern. +11. Moved ItemType and ItemQuality to their own classes to allow re-use +12. Seperated the derived DailyUpdater classes into their own files.
+Now, adding a new updater won't have to change the existing DailyUpdater file.