diff --git a/src/ObserverPattern/ObserverPatternExamples.cs b/src/ObserverPattern/ObserverPatternExamples.cs index faefb00..5004404 100644 --- a/src/ObserverPattern/ObserverPatternExamples.cs +++ b/src/ObserverPattern/ObserverPatternExamples.cs @@ -71,7 +71,6 @@ Concrete Observer -> Implementation of the observer "; } - private static string GetLapsedLinstenerProblem() { return @" @@ -80,6 +79,7 @@ Consequently, the publisher still holds a reference to the observer which preven — including all other objects it is referring to — for as long as the publisher is alive, which could be until the end of the application. This causes not only a memory leak, but also a performance degradation with an 'uninterested' observer receiving and acting on unwanted events"; } + private static void GoToNextStep() { Console.ReadKey(); diff --git a/src/StatePattern/StatePatternExamples.cs b/src/StatePattern/StatePatternExamples.cs index 90c7a56..ebee6fb 100644 --- a/src/StatePattern/StatePatternExamples.cs +++ b/src/StatePattern/StatePatternExamples.cs @@ -10,7 +10,17 @@ namespace StatePattern { public static void Run() { + TVMotivationalExample.Run(); + + GoToNextStep(); + TVExampleRunner.Run(); } + + private static void GoToNextStep() + { + Console.ReadKey(); + Console.Clear(); + } } } diff --git a/src/StatePattern/TVExample/ITVState.cs b/src/StatePattern/TVExample/ITVState.cs index d6496fe..c9717e6 100644 --- a/src/StatePattern/TVExample/ITVState.cs +++ b/src/StatePattern/TVExample/ITVState.cs @@ -6,6 +6,9 @@ using System.Threading.Tasks; namespace StatePattern { + /// + /// State interface + /// public interface ITVState { void OnPowerButtonPresed(); diff --git a/src/StatePattern/TVExample/TVContext.cs b/src/StatePattern/TVExample/TVContext.cs index 79c7841..e939bc0 100644 --- a/src/StatePattern/TVExample/TVContext.cs +++ b/src/StatePattern/TVExample/TVContext.cs @@ -6,6 +6,9 @@ using System.Threading.Tasks; namespace StatePattern.TVExample { + /// + /// Context + /// public class TVContext : ITVState { public ITVState TvOnState { get; private set; } diff --git a/src/StatePattern/TVExample/TVMotivationalExample.cs b/src/StatePattern/TVExample/TVMotivationalExample.cs new file mode 100644 index 0000000..27b6312 --- /dev/null +++ b/src/StatePattern/TVExample/TVMotivationalExample.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace StatePattern.TVExample +{ + public class TVMotivationalExample + { + public static void Run() + { + var tvMotivationalContext = new TVMotivationalContext(); + + tvMotivationalContext.OnPowerButtonPresed(); + + tvMotivationalContext.OnPowerButtonPresed(); + + tvMotivationalContext.OnPowerButtonPresed(); + + tvMotivationalContext.OnPowerButtonPresed(); + } + } + + public class TVMotivationalContext + { + bool isTvOn = false; + + public void OnPowerButtonPresed() + { + if(isTvOn) + { + Console.WriteLine("TV turning off"); + isTvOn = false; + } + else + { + Console.WriteLine("Turning TV on"); + isTvOn = true; + } + } + } +} diff --git a/src/StatePattern/TVExample/TVOffState.cs b/src/StatePattern/TVExample/TVOffState.cs index 9196063..d5af7a6 100644 --- a/src/StatePattern/TVExample/TVOffState.cs +++ b/src/StatePattern/TVExample/TVOffState.cs @@ -6,6 +6,9 @@ using System.Threading.Tasks; namespace StatePattern.TVExample { + /// + /// Concrete state + /// public class TVOffState : ITVState { TVContext context; diff --git a/src/StatePattern/TVExample/TVOnState.cs b/src/StatePattern/TVExample/TVOnState.cs index b9ef1aa..91dbd2b 100644 --- a/src/StatePattern/TVExample/TVOnState.cs +++ b/src/StatePattern/TVExample/TVOnState.cs @@ -6,6 +6,9 @@ using System.Threading.Tasks; namespace StatePattern.TVExample { + /// + /// Concrete state + /// public class TVOnState : ITVState { TVContext context;