mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 14:31:28 +00:00
Seperated the derived DailyUpdater classes into their own files
This commit is contained in:
parent
5e5d6e9fa7
commit
eb741a95c5
@ -28,58 +28,4 @@ public abstract class DailyUpdater
|
|||||||
{
|
{
|
||||||
item.Quality = int.Max(item.Quality - byValue, ItemQuality.MinQuality);
|
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
24
csharpcore/GildedRose/DailyUpdaterForBackstagePassesItems.cs
Normal file
24
csharpcore/GildedRose/DailyUpdaterForBackstagePassesItems.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
namespace GildedRoseKata;
|
||||||
|
|
||||||
|
public class DailyUpdaterForBetterWithAgeItems : DailyUpdater
|
||||||
|
{
|
||||||
|
public override void UpdateQuality(Item item)
|
||||||
|
{
|
||||||
|
IncreaseQuality(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
13
csharpcore/GildedRose/DailyUpdaterForLegendaryItems.cs
Normal file
13
csharpcore/GildedRose/DailyUpdaterForLegendaryItems.cs
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
9
csharpcore/GildedRose/DailyUpdaterForRegularItems.cs
Normal file
9
csharpcore/GildedRose/DailyUpdaterForRegularItems.cs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
namespace GildedRoseKata;
|
||||||
|
|
||||||
|
public class DailyUpdaterForRegularItems : DailyUpdater
|
||||||
|
{
|
||||||
|
public override void UpdateQuality(Item item)
|
||||||
|
{
|
||||||
|
DecreaseQuality(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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>
|
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.
|
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.
|
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.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user