-
리팩토링 : Substitute Algorithm리팩토링 2013. 2. 27. 09:00
조건
알고리즘을 더욱 명료하게 하나로 변경하고 싶으면
적용
메소드의 내용을 새로운 알고리즘으로 변경하시오.
적용전
String foundPerson(String[] people){ for (int i = 0; i < people.length; i++) { if (people[i].equals ("Don")){ return "Don"; } if (people[i].equals ("John")){ return "John"; } if (people[i].equals ("Kent")){ return "Kent"; } } return ""; }
적용후
String foundPerson(String[] people){ List candidates = Arrays.asList(new String[] {"Don", "John", "Kent"}); for (int i=0; i<people.length; i++) if (candidates.contains(people[i])) return people[i]; return ""; }
참조
http://www.refactoring.com/catalog/substituteAlgorithm.html
'리팩토링' 카테고리의 다른 글
리팩토링 : Wrap entities with session (0) 2013.03.01 리팩토링 : Use a Connection Pool (0) 2013.02.28 리팩토링 : Split Temporary Variable (0) 2013.02.26 리팩토링 : Split Loop (0) 2013.02.25 리팩토링 : Separate Query from Modifier (0) 2013.02.24 댓글