중복코드
-
오브젝트 5 - 상속 vs. 합성책책책 책을 읽읍시다/프로그래밍 2023. 2. 14. 22:15
중복과 상속 중복 코드는 변경을 방해한다. 이것이 중복 코드를 제거해야 하는 가장 큰 이유다. 중복 코드가 가지는 가장 큰 문제는 코드를 수정하는 데 필요한 노력을 몇 배로 증가시킨다는 것이다. 우선 어떤 코드가 중복인지를 찾아야 한다. 일단 중복 코드의 묶음을 찾았다면 찾아낸 모든 코드를 일관되게 수정해야 한다. 모든 중복 코드를 개별적으로 테스트해서 동일한 결과를 내놓는지 확인애야만한다. 중복 코드는 수정과 테스트에 드는 비용을 증가시킬뿐만 아니라 시스템과 우리를 공황상태로 몰아넣을 수도 있다. 이번 예제는 한 달에 한 번씩 가입자별로 전화 요금을 계산하는 애플리케이션이다. 전화 요금을 계산하는 규칙은 통화 시간을 단위 시간당 요금으로 나눠주면 된다. 10초당 5원의 통화료를 부과하는 요금제에 가입돼..