是否有任何设计模式/方法/方法来删除嵌套if else else condition/switch语句?
我记得在谷歌代码博客文章中列出的谷歌人使用的一些方法.现在似乎无法找到它
以下两个switch/case语句的更好实践是什么?
有没有更简单的方法(更少的代码)来做到这一点?
switch (myValue)
{
case 1:
{
methodFor1();
break;
}
case 2:
case 3:
{
methodFor2or3();
if (myValue == 2)
methodFor2();
if (myValue == 3)
methodFor3();
break;
}
}
...or...
switch (myValue)
{
case 1:
{
methodFor1();
break;
}
case 2:
case 3:
{
methodFor2or3();
switch (myValue)
{
case 2:
{
methodFor2();
break;
}
case 3:
{
methodFor3();
break;
}
}
break;
}
}
Run Code Online (Sandbox Code Playgroud)