TIL

아이템 19 knowledge를 반복하여 사용하지 말라

프로젝트에서 이미 있던 코드를 복사해서 붙여넣고 있다면, 무언가가 잘못된 것이다.

Knowledge

모든 것은 변화한다

언제 코드를 반복해도 될까?

단일 책임 원칙

class Student {
	// ...
	
	fun isPassing(): Boolean = // 인증 관련 부서가 사용
		calculatePointsFromPassedCourses() > 15
		
	fun qualifiesForScholarship(): Boolean = // 장학금 관련 부서에서 사용
		claculatePointsFromPassedCourses() > 30
		
	private fun claculatePointsFromPassedCourses(): Int { // 각 프로퍼티가 사용하는 공통 로직
		// ...
	}
}
// accreditations 모듈
fun Student.qualifiesForScholarship(): Boolean { 
	/*...*/
}

// scholarship 모듈
fun Student.calculatePointsFromPassedCourses(): Boolean { 
	/*...*/
}