修改前
namespace CleanCSharp.Methods.Dirty
{
class BooleanSwitchingArgumentsExample
{
public void CallingCode()
{
if (DateTime.Now.Hour < 12)
{
OutputGreeting(true);
}
else
{
OutputGreeting(false);
}
}
public void OutputGreeting(bool isMorning)
{
if (isMorning)
{
Console.WriteLine("Good Morning");
}
else
{
Console.WriteLine("Good Day");
}
}
}
}
//修改后
namespace CleanCSharp.Methods.Clean { class BooleanSwitchingArgumentsExample { public void CallingCode() { if (DateTime.Now.Hour < 12) { OutputMorningGreeting(); } else { OutputDaytimeGreeting(); } } private static void OutputDaytimeGreeting() { Console.WriteLine("Good Day"); } private static void OutputMorningGreeting() { Console.WriteLine("Good Morning"); } } }