Skip to content

Instantly share code, notes, and snippets.

@DannyRusnok
Last active May 6, 2020 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DannyRusnok/8b1a44ee6a5b808404a16abb3050e5d6 to your computer and use it in GitHub Desktop.
Save DannyRusnok/8b1a44ee6a5b808404a16abb3050e5d6 to your computer and use it in GitHub Desktop.
State Pattern - Bark State
public class BarkState : IDogState
{
public void EnterState(DogContext context)
{
context.StartBarking();
/*etc these are examples what might a Dog class do*/
}
public void Bark(DogContext context) { throw new NotSupportStateTransitionException(); }
public void Sleep(DogContext context)
{
context.StopBarking();
context.TransitionToState(new SleepState());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment