难于理解的复杂表达式
if ((platform.toUpperCase().indexOf("MAC") > -1) &&
(brower.toUpperCase().indexOf("IE") > -1) &&
wasInitialized && resize > 0) {
// do something
}
重构后
final boolean isMacOS = platform.toUpperCase().indexOf("MAC") > -1;
final boolean isIEBrowser = brower.toUpperCase().indexOf("IE") > -1;
final boolean wasResized = resize > 0;
if (isMacOS && isIEBrowser && wasInitialized() && wasResized) {
// do something
}