Improved global constants located in one place.

This commit is contained in:
israel 2017-10-20 11:51:20 +01:00
parent c54699a410
commit 20538bf65c
7 changed files with 34 additions and 26 deletions

View File

@ -1,4 +1,5 @@
using System;
using csharp.StrategyPatternExample.Strategy;
using System;
using System.Collections.Generic;
namespace csharp.StrategyPatternExample
@ -28,9 +29,7 @@ namespace csharp.StrategyPatternExample
return _strategiesFactory;
}
#endregion
public List<ICategoryStrategy> GetCategoryStrategies(Item item)
{
List<ICategoryStrategy> listCategoryStrategies = new List<ICategoryStrategy>();
@ -73,5 +72,7 @@ namespace csharp.StrategyPatternExample
return listCategoryStrategies;
}
#endregion
}
}

View File

@ -0,0 +1,10 @@
using System;
namespace csharp.StrategyPatternExample
{
static public class Global
{
public const int MAXIMUN_QUALITY = 50;
public const int MINIMUN_QUALITY = 0;
}
}

View File

@ -1,6 +1,6 @@
using System;
namespace csharp.StrategyPatternExample
namespace csharp.StrategyPatternExample.Strategy
{
class NextExpiredImproveQualityStrategy : ICategoryStrategy
{
@ -10,7 +10,7 @@ namespace csharp.StrategyPatternExample
if (item.SellIn < 0)
{
item.Quality = 0;
item.Quality = Global.MINIMUN_QUALITY;
}
else
{
@ -27,9 +27,9 @@ namespace csharp.StrategyPatternExample
item.Quality += inc;
if (item.Quality > 50)
if (item.Quality > Global.MAXIMUN_QUALITY)
{
item.Quality = 50;
item.Quality = Global.MAXIMUN_QUALITY;
}
}
}

View File

@ -1,19 +1,19 @@
using System;
namespace csharp.StrategyPatternExample
namespace csharp.StrategyPatternExample.Strategy
{
class NormalDegradeStrategy : ICategoryStrategy
{
public void Update(Item item)
{
if (item.Quality > 0)
if (item.Quality > Global.MINIMUN_QUALITY)
{
item.Quality--;
}
item.SellIn--;
if (item.SellIn < 0 && item.Quality > 0)
if (item.SellIn < 0 && item.Quality > Global.MINIMUN_QUALITY)
{
item.Quality--;
}

View File

@ -1,23 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace csharp.StrategyPatternExample
namespace csharp.StrategyPatternExample.Strategy
{
class OlderIsBetterStrategy : ICategoryStrategy
{
public void Update(Item item)
{
if (item.Quality < 50)
if (item.Quality < Global.MAXIMUN_QUALITY)
{
item.Quality++;
}
item.SellIn--;
if (item.SellIn < 0 && item.Quality < 50)
if (item.SellIn < 0 && item.Quality < Global.MAXIMUN_QUALITY)
{
item.Quality++;
}

View File

@ -1,6 +1,6 @@
using System;
namespace csharp.StrategyPatternExample
namespace csharp.StrategyPatternExample.Strategy
{
class TwiceFastDegradeQualityStrategy : ICategoryStrategy
{
@ -15,14 +15,14 @@ namespace csharp.StrategyPatternExample
degrade = 4;
}
if (item.Quality > 0)
if (item.Quality > Global.MINIMUN_QUALITY)
{
item.Quality -= degrade;
}
if (item.Quality < 0)
if (item.Quality < Global.MINIMUN_QUALITY)
{
item.Quality = 0;
item.Quality = Global.MINIMUN_QUALITY;
}
}
}

View File

@ -70,14 +70,15 @@
<Compile Include="IGildedRoseApp.cs" />
<Compile Include="Item.cs" />
<Compile Include="StrategyPatternExample\CategoryStrategiesFactory.cs" />
<Compile Include="StrategyPatternExample\Global.cs" />
<Compile Include="StrategyPatternExample\ICategoryStrategy.cs" />
<Compile Include="StrategyPatternExample\ItemWrapperContext.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="StrategyPatternExample\NextExpiredImproveQualityStrategy.cs" />
<Compile Include="StrategyPatternExample\NormalDegradeStrategy.cs" />
<Compile Include="StrategyPatternExample\OlderIsBetterStrategy.cs" />
<Compile Include="StrategyPatternExample\TwiceFastDegradeQualityStrategy.cs" />
<Compile Include="StrategyPatternExample\Strategies\NextExpiredImproveQualityStrategy.cs" />
<Compile Include="StrategyPatternExample\Strategies\NormalDegradeStrategy.cs" />
<Compile Include="StrategyPatternExample\Strategies\OlderIsBetterStrategy.cs" />
<Compile Include="StrategyPatternExample\Strategies\TwiceFastDegradeQualityStrategy.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />