执行此操作时,不要使用“if”|if(s == “value1”){...} else if(s == “value2”) { ...}
根据反 if 运动,在我们的代码中不使用 ifs 是一种最佳做法。谁能告诉我是否有可能摆脱这段代码中的if?(switch也不是一个选项,关键是要去掉条件逻辑,而不是用类似的语言结构替换ifs。)
if(s == "foo")
{
Writeln("some logic here");
}
else if(s == "bar")
{
Writeln("something else here");
}
else if(s == "raboof")
{
Writeln("of course I need more than just Writeln");
}
(语言:Java 或 C#)