الگوی وضعیت State Pattern
نویسنده: علی یگانه مقدم
تاریخ: ۱۳۹۵/۰۱/۲۵ ۱:۲۵
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
public interface IState
{
void PressPlay(MP3PlayerContext context);
} public class MP3PlayerContext
{
public MP3PlayerContext()
{
this.CurrentState = new StandbyState();
}
public MP3PlayerContext(IState state)
{
this.CurrentState = state;
}
public IState CurrentState { get; set; }
public void Play()
{
this.CurrentState.PressPlay(this);
}
} public class StandbyState : IState
{
public void PressPlay(MP3PlayerContext context)
{
context.CurrentState = new PlayingState();
}
}
public class PlayingState : IState
{
public void PressPlay(MP3PlayerContext context)
{
context.CurrentState = new StandbyState();
}
}