mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-16 15:01:28 +00:00
- refactor the UpdateQuality method by : * removing all static item names * strongly typing the different items * moving specific business logic inside the business object
59 lines
1.4 KiB
C#
59 lines
1.4 KiB
C#
using System.Collections.Generic;
|
|
|
|
namespace GildedRoseKata
|
|
{
|
|
public class GildedRose
|
|
{
|
|
private readonly IList<Item> Items;
|
|
public GildedRose(IList<Item> Items)
|
|
{
|
|
this.Items = Items;
|
|
}
|
|
|
|
public void UpdateQuality()
|
|
{
|
|
for (var i = 0; i < Items.Count; i++)
|
|
{
|
|
switch (Items[i])
|
|
{
|
|
case LegendaryItem l: break;
|
|
case AgingItem a:
|
|
a.SetAgingItemQuality();
|
|
break;
|
|
case ConjuredItem c:
|
|
DecreaseItemProperties(c);
|
|
DecreaseItemQuality(c);
|
|
break;
|
|
default:
|
|
DecreaseItemProperties(Items[i]);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void DecreaseItemProperties(Item item)
|
|
{
|
|
DecreaseItemQuality(item);
|
|
DecreateItemSellIn(item);
|
|
DecreaseItemQuality(item);
|
|
}
|
|
|
|
private void DecreaseItemQuality(Item item)
|
|
{
|
|
if (item.Quality > 0)
|
|
{
|
|
item.Quality--;
|
|
}
|
|
}
|
|
|
|
private void DecreateItemSellIn(Item item)
|
|
{
|
|
if (item is not LegendaryItem)
|
|
{
|
|
item.SellIn--;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|