diff --git a/csharpcore/GildedRose/DailyUpdater.cs b/csharpcore/GildedRose/DailyUpdater.cs index 78c862fc..ea49dccc 100644 --- a/csharpcore/GildedRose/DailyUpdater.cs +++ b/csharpcore/GildedRose/DailyUpdater.cs @@ -4,9 +4,6 @@ namespace GildedRoseKata; public abstract class DailyUpdater { - private const int MinQuality = 0; - private const int MaxQuality = 50; - public void DailyUpdate(Item item) { UpdateSellIn(item); @@ -24,12 +21,12 @@ public abstract class DailyUpdater protected static void IncreaseQuality(Item item, int byValue = 1) { - item.Quality = int.Min(item.Quality + byValue, MaxQuality); + item.Quality = int.Min(item.Quality + byValue, ItemQuality.MaxQuality); } protected static void DecreaseQuality(Item item, int byValue = 1) { - item.Quality = int.Max(item.Quality - byValue, MinQuality); + item.Quality = int.Max(item.Quality - byValue, ItemQuality.MinQuality); } } diff --git a/csharpcore/GildedRose/DailyUpdaterFactory.cs b/csharpcore/GildedRose/DailyUpdaterFactory.cs index 47efd08f..e6b2596d 100644 --- a/csharpcore/GildedRose/DailyUpdaterFactory.cs +++ b/csharpcore/GildedRose/DailyUpdaterFactory.cs @@ -5,37 +5,30 @@ namespace GildedRoseKata; public class DailyUpdaterFactory { - private enum ItemType - { - Regular, - Legendary, - BetterWithAge, - BackstagePasses - } - - private readonly Dictionary _dailyUpdaters = new(); + + private readonly Dictionary _dailyUpdaters = new(); public DailyUpdater GetDailyUpdater(Item item) { - if (IsLegendaryItem(item)) + if (ItemType.IsLegendaryItem(item)) { - return GetOrCreateDailyUpdater(ItemType.Legendary, () => new DailyUpdaterForLegendaryItems()); + return GetOrCreateDailyUpdater(ItemType.ItemKey.Legendary, () => new DailyUpdaterForLegendaryItems()); } - if (IsBetterWithAgeItem(item)) + if (ItemType.IsBetterWithAgeItem(item)) { - return GetOrCreateDailyUpdater(ItemType.BetterWithAge, () => new DailyUpdaterForBetterWithAgeItems()); + return GetOrCreateDailyUpdater(ItemType.ItemKey.BetterWithAge, () => new DailyUpdaterForBetterWithAgeItems()); } - if(IsBackstagePassesItem(item)) + if(ItemType.IsBackstagePassesItem(item)) { - return GetOrCreateDailyUpdater(ItemType.BackstagePasses, () => new DailyUpdaterForBackstagePassesItems()); + return GetOrCreateDailyUpdater(ItemType.ItemKey.BackstagePasses, () => new DailyUpdaterForBackstagePassesItems()); } - return GetOrCreateDailyUpdater(ItemType.Regular, () => new DailyUpdaterForRegularItems()); + return GetOrCreateDailyUpdater(ItemType.ItemKey.Regular, () => new DailyUpdaterForRegularItems()); } - private DailyUpdater GetOrCreateDailyUpdater(ItemType itemType, Func createDailyUpdater) + private DailyUpdater GetOrCreateDailyUpdater(ItemType.ItemKey itemType, Func createDailyUpdater) { if (!_dailyUpdaters.ContainsKey(itemType)) { @@ -44,11 +37,4 @@ public class DailyUpdaterFactory return _dailyUpdaters[itemType]; } - - private static bool IsLegendaryItem(Item item) => item.Name.ToLower().Contains("sulfuras"); - - private static bool IsBackstagePassesItem(Item item) => item.Name.ToLower().Contains("backstage passes"); - - private static bool IsBetterWithAgeItem(Item item) => item.Name.ToLower().Equals("aged brie"); - } \ No newline at end of file diff --git a/csharpcore/GildedRose/ItemQuality.cs b/csharpcore/GildedRose/ItemQuality.cs new file mode 100644 index 00000000..ea309d63 --- /dev/null +++ b/csharpcore/GildedRose/ItemQuality.cs @@ -0,0 +1,9 @@ +namespace GildedRoseKata; + +public static class ItemQuality +{ + public const int MinQuality = 0; + public const int MaxQuality = 50; + public const int LegendaryItemQuality = 80; + +} \ No newline at end of file diff --git a/csharpcore/GildedRose/ItemType.cs b/csharpcore/GildedRose/ItemType.cs new file mode 100644 index 00000000..138b4322 --- /dev/null +++ b/csharpcore/GildedRose/ItemType.cs @@ -0,0 +1,20 @@ +namespace GildedRoseKata; + +public static class ItemType +{ + public enum ItemKey + { + Regular, + Legendary, + BetterWithAge, + BackstagePasses + } + + public static bool IsLegendaryItem(Item item) => IsLegendaryItem(item.Name); + public static bool IsLegendaryItem(string name) => name.ToLower().Contains("sulfuras"); + + public static bool IsBackstagePassesItem(Item item) => item.Name.ToLower().Contains("backstage passes"); + + public static bool IsBetterWithAgeItem(Item item) => item.Name.ToLower().Equals("aged brie"); + +} \ No newline at end of file