Last active
January 19, 2017 23:32
-
-
Save Porges/1dc626b8eacf01421f89df1851d5f6bd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| abstract class State | |
| { | |
| public abstract bool IsFinalState { get; } | |
| public abstract bool IsValidTransition(State next); | |
| public abstract override string ToString(); | |
| public static State NotStarted { get; } = new NotStartedT(); | |
| public static State Running { get; } = new RunningT(); | |
| public static State Errored { get; } = new ErroredT(); | |
| public static State Completed { get; } = new CompletedT(); | |
| private abstract class FinalState : State | |
| { | |
| public override bool IsFinalState => true; | |
| public override bool IsValidTransition(State next) => false; | |
| } | |
| private sealed class ErroredT : FinalState | |
| { | |
| public override string ToString() => "Errored"; | |
| } | |
| private sealed class CompletedT : FinalState | |
| { | |
| public override string ToString() => "Completed"; | |
| } | |
| private sealed class RunningT : State | |
| { | |
| public override bool IsFinalState => false; | |
| public override bool IsValidTransition(State next) | |
| => next == Completed || next == Errored; | |
| public override string ToString() => "Running"; | |
| } | |
| private sealed class NotStartedT : State | |
| { | |
| public override bool IsFinalState => false; | |
| public override bool IsValidTransition(State next) | |
| => next == Running || next == Errored; | |
| public override string ToString() => "Not Started"; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment