From 20538bf65c2f7adaceab1af2e5c3ffc6721eaff5 Mon Sep 17 00:00:00 2001 From: israel Date: Fri, 20 Oct 2017 11:51:20 +0100 Subject: [PATCH] Improved global constants located in one place. --- .../CategoryStrategiesFactory.cs | 9 +++++---- csharp/StrategyPatternExample/Global.cs | 10 ++++++++++ .../NextExpiredImproveQualityStrategy.cs | 8 ++++---- .../{ => Strategies}/NormalDegradeStrategy.cs | 6 +++--- .../{ => Strategies}/OlderIsBetterStrategy.cs | 10 +++------- .../TwiceFastDegradeQualityStrategy.cs | 8 ++++---- csharp/csharp.csproj | 9 +++++---- 7 files changed, 34 insertions(+), 26 deletions(-) create mode 100644 csharp/StrategyPatternExample/Global.cs rename csharp/StrategyPatternExample/{ => Strategies}/NextExpiredImproveQualityStrategy.cs (73%) rename csharp/StrategyPatternExample/{ => Strategies}/NormalDegradeStrategy.cs (63%) rename csharp/StrategyPatternExample/{ => Strategies}/OlderIsBetterStrategy.cs (55%) rename csharp/StrategyPatternExample/{ => Strategies}/TwiceFastDegradeQualityStrategy.cs (65%) diff --git a/csharp/StrategyPatternExample/CategoryStrategiesFactory.cs b/csharp/StrategyPatternExample/CategoryStrategiesFactory.cs index 2166b7f2..130271b2 100644 --- a/csharp/StrategyPatternExample/CategoryStrategiesFactory.cs +++ b/csharp/StrategyPatternExample/CategoryStrategiesFactory.cs @@ -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 GetCategoryStrategies(Item item) { List listCategoryStrategies = new List(); @@ -73,5 +72,7 @@ namespace csharp.StrategyPatternExample return listCategoryStrategies; } + + #endregion } } diff --git a/csharp/StrategyPatternExample/Global.cs b/csharp/StrategyPatternExample/Global.cs new file mode 100644 index 00000000..38beae85 --- /dev/null +++ b/csharp/StrategyPatternExample/Global.cs @@ -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; + } +} diff --git a/csharp/StrategyPatternExample/NextExpiredImproveQualityStrategy.cs b/csharp/StrategyPatternExample/Strategies/NextExpiredImproveQualityStrategy.cs similarity index 73% rename from csharp/StrategyPatternExample/NextExpiredImproveQualityStrategy.cs rename to csharp/StrategyPatternExample/Strategies/NextExpiredImproveQualityStrategy.cs index 21fbb2bf..46b30a26 100644 --- a/csharp/StrategyPatternExample/NextExpiredImproveQualityStrategy.cs +++ b/csharp/StrategyPatternExample/Strategies/NextExpiredImproveQualityStrategy.cs @@ -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; } } } diff --git a/csharp/StrategyPatternExample/NormalDegradeStrategy.cs b/csharp/StrategyPatternExample/Strategies/NormalDegradeStrategy.cs similarity index 63% rename from csharp/StrategyPatternExample/NormalDegradeStrategy.cs rename to csharp/StrategyPatternExample/Strategies/NormalDegradeStrategy.cs index 3a0ea630..e52bb555 100644 --- a/csharp/StrategyPatternExample/NormalDegradeStrategy.cs +++ b/csharp/StrategyPatternExample/Strategies/NormalDegradeStrategy.cs @@ -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--; } diff --git a/csharp/StrategyPatternExample/OlderIsBetterStrategy.cs b/csharp/StrategyPatternExample/Strategies/OlderIsBetterStrategy.cs similarity index 55% rename from csharp/StrategyPatternExample/OlderIsBetterStrategy.cs rename to csharp/StrategyPatternExample/Strategies/OlderIsBetterStrategy.cs index 89d1a1d1..7414c008 100644 --- a/csharp/StrategyPatternExample/OlderIsBetterStrategy.cs +++ b/csharp/StrategyPatternExample/Strategies/OlderIsBetterStrategy.cs @@ -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++; } diff --git a/csharp/StrategyPatternExample/TwiceFastDegradeQualityStrategy.cs b/csharp/StrategyPatternExample/Strategies/TwiceFastDegradeQualityStrategy.cs similarity index 65% rename from csharp/StrategyPatternExample/TwiceFastDegradeQualityStrategy.cs rename to csharp/StrategyPatternExample/Strategies/TwiceFastDegradeQualityStrategy.cs index a03fcff1..5b45df35 100644 --- a/csharp/StrategyPatternExample/TwiceFastDegradeQualityStrategy.cs +++ b/csharp/StrategyPatternExample/Strategies/TwiceFastDegradeQualityStrategy.cs @@ -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; } } } diff --git a/csharp/csharp.csproj b/csharp/csharp.csproj index f8655672..34b7076f 100644 --- a/csharp/csharp.csproj +++ b/csharp/csharp.csproj @@ -70,14 +70,15 @@ + - - - - + + + +