Created
August 26, 2014 12:29
-
-
Save FaronBracy/f295950ce4416cdf0ef1 to your computer and use it in GitHub Desktop.
Jon Skeet's Clever Enum
This file contains 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
public class MyCleverEnum | |
{ | |
public static readonly MyCleverEnum First = new FirstCleverEnum(); | |
public static readonly MyCleverEnum Second = new SecondCleverEnum(); | |
// Can only be called by this type *and nested types* | |
private MyCleverEnum() | |
{ | |
} | |
public abstract void SomeMethod(); | |
public abstract void AnotherMethod(); | |
private class FirstCleverEnum : MyCleverEnum | |
{ | |
public override void SomeMethod() | |
{ | |
// First-specific behaviour here | |
} | |
public override void AnotherMethod() | |
{ | |
// First-specific behaviour here | |
} | |
} | |
private class SecondCleverEnum : MyCleverEnum | |
{ | |
public override void SomeMethod() | |
{ | |
// Second-specific behaviour here | |
} | |
public override void AnotherMethod() | |
{ | |
// Second-specific behaviour here | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment