Skip to content

Commit

Permalink
r Shift MultipleOfThree_RuleEvalAction to use Base
Browse files Browse the repository at this point in the history
  • Loading branch information
Fyzxs committed Dec 8, 2021
1 parent 1b5dfb0 commit f388e95
Showing 1 changed file with 5 additions and 23 deletions.
28 changes: 5 additions & 23 deletions TddLikeYouMeanIt/RuleEvalAction.cs
Expand Up @@ -15,29 +15,6 @@ public Answer Act(TurnCount turnCount)
}
}

public sealed class MultipleOfThree_RuleEvalAction : IRuleEvalAction
{
private readonly IRule _rule;
private readonly IRuleEvalAction _nextAction;

public MultipleOfThree_RuleEvalAction(IRuleEvalAction nextAction) : this(new MultipleOfThreeRule(), nextAction) { }

private MultipleOfThree_RuleEvalAction(IRule rule, IRuleEvalAction nextAction)
{
_rule = rule;
_nextAction = nextAction;
}

public Answer Act(TurnCount turnCount)
{
if (ShouldHandle(turnCount)) return new FizzAnswer();

return _nextAction.Act(turnCount);
}

private bool ShouldHandle(TurnCount turnCount) => _rule.Matches(turnCount);
}

public abstract class Base_RuleEvalAction : IRuleEvalAction
{
private readonly IRule _rule;
Expand All @@ -61,6 +38,11 @@ public Answer Act(TurnCount turnCount)
private bool ShouldHandle(TurnCount turnCount) => _rule.Matches(turnCount);
}

public sealed class MultipleOfThree_RuleEvalAction : Base_RuleEvalAction
{
public MultipleOfThree_RuleEvalAction(IRuleEvalAction nextAction) : base(new MultipleOfThreeRule(), new FizzAnswer(), nextAction) { }
}

public sealed class MultipleOfFive_RuleEvalAction : Base_RuleEvalAction
{
public MultipleOfFive_RuleEvalAction(IRuleEvalAction nextAction) : base(new MultipleOfFiveRule(), new BuzzAnswer(), nextAction) { }
Expand Down

0 comments on commit f388e95

Please sign in to comment.