【发布时间】:2016-01-21 09:28:10
【问题描述】:
我有如下接口和实现。 如果一个数字可以被除数整除,它将显示名为“可除数”的内容。 现在新的增强功能出现在我需要根据时间更改文本的地方。 如果数字是可整除的,并且时间是 12:00 PM,则显示“Divisible ***”。如果时间不是“12:PM”,则显示旧值,即“Divisible”。 我知道可以做到,但条件是我们不应该违反SOLID原则。我所做的设计是否错误?请提出建议。
public interface IRule
{
string GetResult(int number);
}
public class DivisibleRule : IRule
{
private readonly int divisor;
private readonly string contentToDisplay;
private readonly string replacementContent;
public DivisibleRule(int divisor, string contentToDisplay)
{
this.divisor = divisor;
this.contentToDisplay = contentToDisplay;
}
/// <summary>
/// Gets the result.
/// </summary>
/// <param name="input">The input.</param>
/// <returns>Returns the content if divisible.</returns>
public string GetResult(int input)
{
return input % this.divisor == 0
? this.contentToDisplay
: string.Empty;
}
}
【问题讨论】:
标签: c# architecture solid-principles