-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9635955
commit 4b23c30
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |