2
我有和接口和实现如下。 如果一个数字可以被顾问整除,它将显示名为“可分割”的内容。 现在,新的增强功能出现在我需要根据时间更改文字的地方。 如果数字是可以整除的,并且时间是12:00 PM,则显示“可分割***”。如果时间不是“12:PM”,则显示旧值i:e“可分割”。 我知道它可以做到,但条件是我们不应该违反SOLID原则。我所做的设计是错误的吗?请建议。在不违反SOLID原则的情况下添加条件逻辑C#
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;
}
}