🤔 생성자 주입과 컴포지션 무엇을 선택해야할까 ?

💉 생성자 주입

class ViewController(
    private val inputView: InputView,
    private val outputView: OutputView
) 

🩻 컴포지션

class ViewController {
    private val inputView = InputView("페토")
    private val outputView = OutputView()
}

<aside> 💡

컴포지션에 대해 더 알고싶다면 ? Effective Kotlin Item 35. 상속보다 컴포지션을 사용하라

</aside>

📕 Example scenario

class Student(
    val name: String,
    val age: Int
//  val hoby: String    
)

class Inject(val item: Student) {  }

class Composition { 
	val item = Student("페토", 20) 
}

컴포지션일 때

class Student(
    val name: String,
    val age: Int
    val hoby: String
)

class Composition { 
	val items = Student("페토", 99, "축구") 
}

🤝 결합도(Coupling)란?

<aside> 💡

결합도와 응집도가 왜 중요한지 궁금하다면 ? https://medium.com/@soqlehsoqleh/solid-a3717cb99ae8

</aside>