using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace stateTest
{
class Program
{
static void Main(string[] args)
{
Light light = new Light();
light.PressSwtich();
light.PressSwtich();
light.PressSwtich();
Console.ReadLine();
}
}
public interface LightState
{
void pressSwitch(Light lingt);
}
public class lightOn : LightState
{
public void pressSwitch(Light lingt)
{
Console.WriteLine("Light Off");
lingt.State=new LightOff();
}
}
public class LightOff : LightState
{
public void pressSwitch(Light lingt)
{
Console.WriteLine("Light On");
lingt.State = new lightOn();
}
}
public class Light {
public LightState State;
public Light()
{
State = new LightOff();
}
public void PressSwtich()
{
State.pressSwitch(this);
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace stateTest
{
class Program
{
static void Main(string[] args)
{
Light light = new Light();
light.PressSwtich();
light.PressSwtich();
light.PressSwtich();
Console.ReadLine();
}
}
public interface LightState
{
void pressSwitch(Light lingt);
}
public class lightOn : LightState
{
public void pressSwitch(Light lingt)
{
Console.WriteLine("Light Off");
lingt.State=new LightOff();
}
}
public class LightOff : LightState
{
public void pressSwitch(Light lingt)
{
Console.WriteLine("Light On");
lingt.State = new lightOn();
}
}
public class Light {
public LightState State;
public Light()
{
State = new LightOff();
}
public void PressSwtich()
{
State.pressSwitch(this);
}
}
}