Exemple #1
0
        // TODO: when FizzBuzzEngineFactory is gone,
        // refactor to GetSolver<FizzBuzzRuleSet>()
        // and use service locator to resolve other dependencies.
        public IFizzBuzzSolver GetSolver(FizzBuzzRuleSet ruleSet)
        {
            IFizzBuzzSolver solver = null;

            switch (ruleSet)
            {
            /// <summary>
            /// The standard game - based on the divisibility of a number.
            /// </summary>
            case FizzBuzzRuleSet.FizzBuzzDivisible:
                solver = new FizzBuzzDivisibleSolver();
                break;

            /// <summary>
            /// The standard game with additional substitutions for divisibility.
            /// </summary>
            case FizzBuzzRuleSet.FizzBuzzBoomBangCrashDivisible:
                solver = new FizzBuzzCrashDivisbleSolver();
                break;

            /// <summary>
            /// A game based on the digits contained in a number.
            /// </summary>
            case FizzBuzzRuleSet.FizzBuzzDigits:
                solver = new FizzBuzzDigitsSolver();
                break;

            /// <summary>
            /// A combination of FizzBuzzDivisible and FizzBuzzDigits.
            /// </summary>
            case FizzBuzzRuleSet.FizzBuzzDivisibleOrDigits:
                solver = new FizzBuzzDivisibleOrDigitsSolver(new FizzBuzzDivisibleSolver(), new FizzBuzzDigitsSolver());
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(ruleSet), $"{ruleSet} is not a handled {nameof(ruleSet)}");                 // <-- ASSUME: C# 7 compiler
            }
            return(solver);
        }
Exemple #2
0
 public FizzBuzzDivisibleOrDigitsSolver(FizzBuzzDivisibleSolver fizzBuzzDivisibleSolver, FizzBuzzDigitsSolver fizzBuzzDigitsSolver)
 {
     this.fizzBuzzDivisibleSolver = fizzBuzzDivisibleSolver;
     this.fizzBuzzDigitsSolver    = fizzBuzzDigitsSolver;
 }