标签:des style blog io color sp div log bs
void Main() { Subject subject = new Subject{ Level=10 }; State sa = new StateA(); State sb = new StateB(); State sc = new StateC(); sa.Set(sb); sb.Set(sc); sa.Show(subject); } class Subject{ public int Level { get; set; } } abstract class State{ protected State superior; public void Set(State s){ superior = s;} public abstract void Show(Subject subject); } class StateA:State{ public override void Show(Subject subject){ if (subject.Level<=10){} else if(superior!=null){ superior.Show(subject); } } } class StateB:State{ public override void Show(Subject subject){ if (subject.Level<=100){} else if(superior!=null){ superior.Show(subject); } } } class StateC:State{ public override void Show(Subject subject){ if (subject.Level<=1000){} else if(superior!=null){ superior.Show(subject); } } }
DesignPattern_Behavioral_State
标签:des style blog io color sp div log bs
原文地址:http://www.cnblogs.com/rammderek/p/4103138.html