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;
}
}