請賜教:Java:代碼重構/優化
您更喜歡哪一個?爲什麼? [可讀性?記憶關注?其他一些問題?]
String strSomething1 = someObject.getSomeProperties1();
strSomething1 = doSomeValidation(strSomething1);
String strSomething2 = someObject.getSomeProperties2();
strSomething2 = doSomeValidation(strSomething2);
String strSomeResult = strSomething1 + strSomething2;
someObject.setSomeProperties(strSomeResult);
2.
someObject.setSomeProperties(doSomeValidation(someObject.getSomeProperties1()) +
doSomeValidation(someObject.getSomeProperties2()));
如果你會做一些其他的方式,那會是什麼呢?你爲什麼要那樣做?
當然是一個例子..我刪除它,因爲你可能會想爲什麼我的版本.. :) – DragonBorn 2008-11-25 15:29:08