Seperated the derived DailyUpdater classes into their own files

This commit is contained in:
Sarah Ashri 2024-03-15 11:23:20 +10:00
parent 5e5d6e9fa7
commit eb741a95c5
6 changed files with 59 additions and 55 deletions

View File

@ -29,57 +29,3 @@ 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
}
}

View File

@ -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);
}
}
}

View File

@ -0,0 +1,9 @@
namespace GildedRoseKata;
public class DailyUpdaterForBetterWithAgeItems : DailyUpdater
{
public override void UpdateQuality(Item item)
{
IncreaseQuality(item);
}
}

View File

@ -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
}
}

View File

@ -0,0 +1,9 @@
namespace GildedRoseKata;
public class DailyUpdaterForRegularItems : DailyUpdater
{
public override void UpdateQuality(Item item)
{
DecreaseQuality(item);
}
}

View File

@ -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.<br>
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.<br>
Now, adding a new updater won't have to change the existing DailyUpdater file.