Created
December 22, 2020 13:07
-
-
Save vkhorikov/8b966da515928a6f96f2d7fa28bcd72f to your computer and use it in GitHub Desktop.
A sample implementation of the Enumeration pattern
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
public abstract class PoolType : ValueObject | |
{ | |
public static readonly PoolType Quant = new QuantPoolType(); | |
public static readonly PoolType Verbal = new VerbalPoolType(); | |
public static readonly PoolType IR = new IRPoolType(); | |
public static readonly PoolType Awa = new AwaPoolType(); | |
public static readonly PoolType[] AllTypes = { Quant, Verbal, IR, Awa }; | |
public abstract int Id { get; } | |
public abstract int Size { get; } | |
public abstract bool EnemyListsSupported { get; } | |
public abstract bool ScaledScoresLookupSupported { get; } | |
public abstract bool ScriptsCanRepeatBetweenSessions { get; } | |
public abstract string StringRepresentation { get; } | |
public static PoolType FromId(int id) | |
{ | |
Maybe<PoolType> poolType = AllTypes.SingleOrDefault(x => x.Id == id); | |
return poolType.GetValueOrThrow($"Invalid pool type id: '{id}'"); | |
} | |
public static Maybe<PoolType> FromString(string str) | |
{ | |
return AllTypes.SingleOrDefault(x => x.StringRepresentation.EqualsIgnoreCase(str)); | |
} | |
public abstract (double min, double max) GetStartingThetaRange(); | |
protected override IEnumerable<object> GetEqualityComponents() | |
{ | |
yield return Id; | |
} | |
private sealed class QuantPoolType : PoolType | |
{ | |
public override int Id => 187; | |
public override int Size => 31; | |
public override bool EnemyListsSupported => true; | |
public override bool ScaledScoresLookupSupported => false; | |
public override bool ScriptsCanRepeatBetweenSessions => true; | |
public override string StringRepresentation => "Q"; | |
public override (double min, double max) GetStartingThetaRange() => (0.767, 1.767); | |
} | |
private sealed class VerbalPoolType : PoolType | |
{ | |
public override int Id => 188; | |
public override int Size => 36; | |
public override bool EnemyListsSupported => true; | |
public override bool ScaledScoresLookupSupported => false; | |
public override bool ScriptsCanRepeatBetweenSessions => true; | |
public override string StringRepresentation => "V"; | |
public override (double min, double max) GetStartingThetaRange() => (-0.442, 0.558); | |
} | |
private sealed class IRPoolType : PoolType | |
{ | |
public override int Id => 211; | |
public override int Size => 12; | |
public override bool EnemyListsSupported => false; | |
public override bool ScaledScoresLookupSupported => true; | |
public override bool ScriptsCanRepeatBetweenSessions => false; | |
public override string StringRepresentation => "IR"; | |
public override (double min, double max) GetStartingThetaRange() => (0, 0); | |
} | |
private sealed class AwaPoolType : PoolType | |
{ | |
public override int Id => 186; | |
public override int Size => 1; | |
public override bool EnemyListsSupported => false; | |
public override bool ScaledScoresLookupSupported => false; | |
public override bool ScriptsCanRepeatBetweenSessions => true; | |
public override string StringRepresentation => "Awa"; | |
public override (double min, double max) GetStartingThetaRange() => (0, 0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment