알고리즘을 보다 명확한 것으로 바꾸고 싶을 때는, 메소드의 몸체를 새로운 알고리즘으로 바꾼다.
public string SubstituteAlgorithm_Before(string[] peoples) { for (int i = 0; i < peoples.Length; i++) { if (peoples[i] == "Don") return "Don"; if (peoples[i] == "John") return "John"; if (peoples[i] == "Kent") return "Kent"; } return ""; }
public string SubstituteAlgorithm_After(string[] peoples) { var candidates = new string[] { "Don", "John", "Kent" }; foreach(var people in peoples) { if (candidates.Contains(people)) return people; } return ""; }