Skip to content

Commit

Permalink
Add MaturingItemManager.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
KsiProgramming committed May 20, 2024
1 parent 9635955 commit 4b23c30
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/Core/ProposedCode/MaturingItemManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//-----------------------------------------------------------------------
// <copyright file="MaturingItemManager.cs" company="KsiProgramming">
// Copyright (c) KsiProgramming. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace GildedRoseKata.ProposedCode
{
using GildedRoseKata.OriginalCode;

public class MaturingItemManager
{
private readonly IDictionary<string, IItemMaturingStrategy> strategies;

public MaturingItemManager(IDictionary<string, IItemMaturingStrategy> strategies)
{
this.strategies = strategies;
}

public Item MatureItem(Item item)
{
if (this.strategies.TryGetValue(item.Name, out var strategy))
{
var request = new ItemMaturingRequest(new Quality(item.Quality), new SellIn(item.SellIn));
var response = strategy.Update(request);

return new ()
{
Name = item.Name,
Quality = response.quality.value,
SellIn = response.sellIn.value,
};
}

// Handle case where item type doesn't have a strategy
return item;
}
}
}

0 comments on commit 4b23c30

Please sign in to comment.