Exemple #1
0
 public Rare(double currentTemp, Steak steak)
 {
     this.currentTemp = currentTemp;
     this.steak       = steak;
     // initializing the class fields for this state
     Initialize();
 }
Exemple #2
0
 public Ruined(double currentTemp, Steak steak)
 {
     this.currentTemp = currentTemp;
     this.steak       = steak;
     canEat           = true;
     // initializing the class fields for this state
     Initialize();
 }
Exemple #3
0
        /// <summary>
        /// The State pattern Allow an object to alter its behavior when its internal state changes.
        /// The object will appear to change its class.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            //Let's cook a steak!
            Steak steak = new Steak("T-Bone");

            // Apply temperature changes that will make the class change state
            steak.AddTemp(120);
            steak.AddTemp(15);
            steak.AddTemp(15);
            steak.RemoveTemp(10); //Yes I know cooking doesn't work this way, bear with me.
            steak.RemoveTemp(15);
            steak.AddTemp(20);
            steak.AddTemp(20);
            steak.AddTemp(20);

            Console.ReadKey();
        }